ich habe diesen code: for i, attr in enumerate(table_attributes): in python

The code for i, attr in enumerate(table_attributes): creates a loop that iterates over the table_attributes list and assigns each element of the list to the attr variable, while also giving it an index number through the enumerate() function, which is assigned to the i variable.

Here's an example:

main.py
table_attributes = ['name', 'age', 'gender']

for i, attr in enumerate(table_attributes):
    print(f'{i}. {attr}')

# Output:
# 0. name
# 1. age
# 2. gender
158 chars
10 lines

In this example, the loop iterates over the table_attributes list, assigning each element to attr and its index to i, and prints the index and value of the element in a formatted string.

related categories

gistlibby LogSnag