str.split(sep=None, maxsplit=- 1)
sep ๋ฅผ ๊ตฌ๋ถ์ ๋ฌธ์์ด๋ก ์ฌ์ฉํ์ฌ ๋ฌธ์์ด์ ์๋ ๋จ์ด๋ค์ ๋ฆฌ์คํธ๋ฅผ ๋๋ ค์ค๋๋ค.
a = "Life is too short"
a.split()
์ถ๋ ฅ
['Life', 'is', 'too', 'short']โ
sep์ฌ์ฉ ์์
b = "a:b:c:d"
b.split(':')
์ถ๋ ฅ
['a', 'b', 'c', 'd']
: ๋ฅผ ๊ตฌ๋ถ์๋ก ์ฌ์ฉํ์ฌ ๋ฌธ์์ด์ ๋๋๋๋ค.
str.split() ๊ณผ str.split(" ")์ ์ฐจ์ด
c = "apple banana orange pineapple"
print(c.split())
print(c.split(" "))
์ถ๋ ฅ
['apple', 'banana', 'orange', 'pineapple']
['apple', 'banana', '', 'orange', '', '', 'pineapple']
์ถ๋ ฅ๋ฌธ์ ๋ณด๋ฉด ์ ์ ์๋ฏ์ด (sep=" ")์ผ๋ก ์ง์ ํ๋ฉด split()๊ณผ ๋ค๋ฅด๊ฒ ๊ณต๋ฐฑ๋ ๊ตฌ๋ถ์ด ๋ฉ๋๋ค.
'Study > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Matplotlib] python matplotlib ํ๊ธ ๊นจ์ง ํด๊ฒฐํ๊ธฐ (0) | 2023.03.26 |
---|---|
[python] ๋ ผ๋ฆฌ์ฐ์ฐ์(Logical Operator): AND, OR, NOT, XOR (0) | 2023.03.22 |
[python] ๋น๊ต/๊ด๊ณ ์ฐ์ฐ์ (0) | 2023.03.22 |
[python] ๋นํธ ์ํํธ ์ฐ์ฐ (<<, >>) (0) | 2023.03.21 |
[python] ํ์ด์ฌ ์์์ ์๋ฆฌ(round,format,f-string,'%.nf') (0) | 2023.03.21 |