「Python」splitメソッドで文字列をカンマで区切るサンプル

2020年12月13日

構文
文字列.split(区切り文字列 [,分割数 ])
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
target = '123,abc,test,ark,game'
res = target.split(',')
for el in res:
print("character info: ",el)
# coding: utf-8 #!/usr/bin/python3 target = '123,abc,test,ark,game' res = target.split(',') for el in res: print("character info: ",el)
# coding: utf-8

#!/usr/bin/python3

target = '123,abc,test,ark,game'
res = target.split(',')

for el in res:
      print("character info: ",el)

実行結果
>python test.py
character info: 123
character info: abc
character info: test
character info: ark
character info: game

Python

Posted by arkgame