Ad
2: 2016-12-05 (月) 13:30:02 njf ソース バックアップ No.2 を復元して編集 現: 2017-09-05 (火) 14:40:09 njf ソース 編集
Line 3: Line 3:
 testStr = "a,b,c,d,e,f"  testStr = "a,b,c,d,e,f"
 + 
 print testStr.split(",")  print testStr.split(",")
Line 13: Line 13:
 testStr = "a,b,c,d,e,f"  testStr = "a,b,c,d,e,f"
 + 
 print testStr.split(",",2)  print testStr.split(",",2)
Line 26: Line 26:
 testStr = "123456789"  testStr = "123456789"
 + 
 print list(testStr)  print list(testStr)
Line 32: Line 32:
 ['1', '2', '3', '4', '5', '6', '7', '8', '9']  ['1', '2', '3', '4', '5', '6', '7', '8', '9']
-ただし、Pythonの文字列はもともとリストのような振る舞いをするので、リストに変換してもさほど使い道はないかも知れません。+ただし、Pythonの文字列はもともとリストのような振る舞いをするので、参照するだけならリストに変換してもさほど使い道はないかも知れません。
例えば、文字列のままでループも可能です。 例えば、文字列のままでループも可能です。
 testStr = "123456789"  testStr = "123456789"
 + 
 for c in testStr:  for c in testStr:
     print c      print c
Line 51: Line 51:
 8  8
 9  9
 +
 +しかし、頻繁に大きな文字列を編集するならリストの方が高速なので、その場合に文字列のリストへの変換が役立つことがあります。


トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 2678, today: 2, yesterday: 0
MenuBar
広告

ログイン

ユーザー名:


パスワード:





パスワード紛失

Portuguese | English | German | Greek | Japanese | Korean | Russian | T-Chinese top
NJF