Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Pythonにおける文字列インデックス | セクション
Pythonにおける変数と演算子

bookPythonにおける文字列インデックス

メニューを表示するにはスワイプしてください

文字列内の特定の文字にアクセスするには、角括弧内にインデックス番号を指定して使用します。Pythonはゼロベースのインデックスを採用しており、インデックス番号は文字の位置と直接一致しません。

12345
# The string of digits word = "codefinity" # Access the character at index 1 (second character) print(word[1])
copy

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])
copy
question mark

この文字列において、インデックス [4][-8] の文字は何ですか?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  7

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  7
some-alt