string の split 関数は、区切り文字を指定しない場合には半角スペースや改行・タブ文字を使って自動的に分割してくれる。
分割結果はリストで返される。
例
str1 = 'Hello, nice to\tmeet\nyou.'
str2 = str1.split()
print(str2)
結果
['Hello,', 'nice', 'to', 'meet', 'you.']
雑記
投稿日:2020年12月3日 更新日:
string の split 関数は、区切り文字を指定しない場合には半角スペースや改行・タブ文字を使って自動的に分割してくれる。
分割結果はリストで返される。
str1 = 'Hello, nice to\tmeet\nyou.'
str2 = str1.split()
print(str2)
['Hello,', 'nice', 'to', 'meet', 'you.']
執筆者:seyanen
関連記事
python3 で、配列の最大値のインデックスを1つ求める方法
配列の index() メソッドを使うと、その値のインデックスを求めることができる。 最大値を求めるメソッド max と組み合わせて使う。 例 arr = [2,4,5,10,8,-3] in …
axhline, axvline を使ってx,y軸に平行な線を描くことができる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot …
「linestyle = 」として、線の種類を指定することができる設定の詳細は、次のリンクを参照。 https://matplotlib.org/stable/gallery/lines_bars_a …
readline を使って次のように書く。 例 ファイル:data.txt # id name age 1 佐藤太郎 10 2 鈴木花子 18 3 坂本明美 21 4 松村光子 24 5 小川奏子 1 …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。