LoginSignup
1
1

More than 3 years have passed since last update.

【Python】文字列をsplitする際に、対応する区切り文字が含まれていなかった場合

Last updated at Posted at 2019-09-19

文字列をsplitする際に、区切り文字が含まれていなかった場合の挙動が気になったのでやってみた。

結果

"A:B:C"のような文字列の場合、":"でsplitすると


print("A:B:C".split(":"))

# ["A", "B", "C"]

となり、指定した区切り文字で分割してリストに格納してくれる。

これが、"B"という文字列の場合は":"でsplitするとどうなるか気になったのでやってみた。


print("B".split(":"))

# ["B"]

エラーなくリストに格納してくれた。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1