그전에도 지금도 앞으로도 파이썬 공부는 쭉 계속된다.🚀
파이썬 기반 다지기 공사 들어갑니다.... 영차영차 🧱🧱🧱🧱🧱
split
join
string
list
unpacking
items = 'zero one two three'.split()
print(items)
Out:
['zero', 'one', 'two', 'three']
example = 'python, query, javascript'
print(example.split(','))
Out:
['python,', 'query,', 'javascript']
a, b, c = example.split(',')
print(a, b, c)
Out:
python query javascript
example = 'python.c++.java'
one, two, three = example.split('.')
print(one, two, three)
Out:
python c++ java
-join
: String List를 합쳐 하나의 String으로 반환할 때 사용
colors = ['red', 'blue', 'green', 'yellow']
result = ''.join(colors)
print(result)
Out:
redbluegreenyellow
# 연결 시 빈칸 1칸으로 연결
result = ' '.join(colors)
print(result)
Out:
red blue green yellow
# 연결 시 ", "으로 연결
result = ','.join(colors)
print(result)
Out:
red, blue, green, yellow
result = '-'.join(colors)
result
Out:
red-blue-green-yellow
여기까지 String Type을 List type으로 나누는 함수 split
, List type을 String Type으로 합치는 함수 join
을 살펴보았습니다!
무료 강의입니다! 강추!