python for in文で文字列の1文字ずつ取得
構文
for 文字変数名 in 文字列:
使用例
# coding: utf-8
str = 'testdata'
print("for文で1文字ずつ取得するサンプル")
for s in str:
print (s)
# coding: utf-8
str = 'testdata'
print("for文で1文字ずつ取得するサンプル")
for s in str:
print (s)
# coding: utf-8 str = 'testdata' print("for文で1文字ずつ取得するサンプル") for s in str: print (s)
実行結果
for文で1文字ずつ取得するサンプル
t
e
s
t
d
a
t
a
for文で1文字ずつ取得するサンプル
t
e
s
t
d
a
t
a
for文で1文字ずつ取得するサンプル t e s t d a t a