Pythonにおける文字列インデックス
メニューを表示するにはスワイプしてください
文字列内の特定の文字にアクセスするには、角括弧内にインデックス番号を指定して使用します。Pythonはゼロベースのインデックスを採用しており、インデックス番号は文字の位置と直接一致しません。
12345# The string of digits word = "codefinity" # Access the character at index 1 (second character) print(word[1])
Pythonの負のインデックスを使用すると、末尾から要素にアクセスできます。先頭(インデックス0)からではなく、末尾(インデックス-1)から始まり、これは最後の要素を表します。
12345# The string of digits word = "codefinity" # Access the characters at index -1 and -9 (first and last ones) print(word[-1], word[-10])
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 7
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 1. 章 7