如何访问索引本身以获取如下列表?
ints = [8, 23, 45, 12, 78]
for i in ints:
print('item #{} = {}'.format(???, i))
Run Code Online (Sandbox Code Playgroud)
当我使用循环遍历它时for,如何访问循环索引,在这种情况下从1到5?
之间有什么区别__str__和__repr__在__str__?
我是新来的,也是 Python 的新手。我不知道是什么f在print(f'Column names are {"-".join(row)}')做我试着删除它,然后“列名是{‘ - ’加入(行)}”成为普通的字符串
你能告诉我什么f叫,所以我可以谷歌了解更多信息吗?谢谢你们。
import csv
with open('CSV_test.txt') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
print(f'Column names are {"-".join(row)}')
line_count += 1
else:
print(f'\t{row[0]} works in the {row[1]} '
f'department, and was born in {row[2]}.')
line_count += 1
print(f'Processed {line_count} lines.')
Run Code Online (Sandbox Code Playgroud)