文字列の指定した位置の文字を取り出す String.charAt

テキスト公式データ取得日:2026年11月13日Python:String.char_at動作確認待ち

ひとことで言うと

指定した位置にある文字を返します。

ブロックとコード

ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。

引数(ひきすう)

引数とは、ブロックの中で自分で選んだり入力したりする部分のことです。

名前選べる値意味
index数値目的の文字の位置を 0 から始まる値で指定します。

使用例

You can find out which character is at any place in some text. You might have text thats says "Hello there!". The character at position 6 is 't'. The word "Hello" plus the space have positions 0 - 5, so, 't' is at position 6. To get the character at this position, the letter 't', you could use a blocks like this:

JavaScript

let greeting = "Hello there!";
let tee = greeting.charAt(6);

Python

greeting = "Hello there!"
tee = greeting.char_at(6)

Make a funny new sentence from an existing sentence by choosing every other letter.

JavaScript

let sentence = "Cinnamon vanilla latte";
let funnySentence = "";
for (let i = 0; i < sentence.length; i++) {
    if (i % 2 > 0) {
        funnySentence = funnySentence + sentence.charAt(i);
    }
}

Python

sentence = "Cinnamon vanilla latte"
funnySentence = ""
for i in range(len(sentence)):
    if i % 2 > 0:
        funnySentence = funnySentence + sentence.char_at(i)
執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにMakeCodeを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む