728x90
List comprehension
x = [1,2,3,4]
ls = []
for item in x:
out.append(item**2)
print(out)
>> [1,4,9,16]
[item**2 for item in x]
>> [1,4,9,16]
lambda expressions
ls = [1,2,3,4,5]
list(filter(lambda item: item%2 == 0, ls))
>> [2,4]
Mathods
s = 'Hello professor'
s.lower() # 전체 소문자화
>> 'hello professor'
s.upper() # 전체 대문자화
>> 'HELLO PROFESSOR'
s.split()
>> ['Hello','professor']
p = "Let's go!"
p.split("'") # 따옴표 안에 문자 기준 나누기, 리스트로 출력
>> ['Let', 's go!']
p.split("'")[1]
>> 's go!'
ls = [1,3,5]
ls.pop() # 마지막 원소 출력
>> 5