一行代碼實現列表的逐個元素打印

代碼:python lt = ['a', 'b', 'c', 'd'] print(*[f'{i}\t{item}' for i, item in enumerate(lt)], sep='\n') 輸出:web 0 a 1 b 2 c 3 d 關鍵之處在於print()函數中,列表前面的*,起到解壓列表的做用。 若是沒有*,是下面這樣的結果。svg 代碼:函數 lt = ['a', 'b', '
相關文章
相關標籤/搜索