Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこのコードを持っています:
for i in words: print i
'hello' 単語を 3 回報告します。理由:
for i in words: print i[0]
レポートは 3 回の 'h' 単語であり、1 回の 'hello' 単語ではありませんか? 一度「こんにちは」と報告する必要があります。
コードの動作の説明は次のとおりです。
1. リストのすべての要素をwords2.i この要素を出力
words
i
1. リストのすべての要素をwords2.i の最初の要素をi出力します (たまたま文字列なので、最初の文字が出力されます)
コードを一度だけ印刷するには、リストの最初の要素を印刷するhelloようなことをする必要がありますprint words[0]words
hello
print words[0]