[Python] 알파벳 리스트 만들기

정수연·2023년 6월 23일
0
post-thumbnail

알파벳 리스트를 만드는 코드 (List Comprehension 이용)

import string

# 소문자 리스트
lower = [i for i in string.ascii_lowercase]
print(lower)
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

# 대문자 리스트
upper = [i for i in string.ascii_uppercase]
print(upper)
# ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

# 대문자 + 소문자 전체 리스트
lowup = [i for i in string.ascii_letters]
print(lowup)
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

외워두면 유용할 것 같다!

0개의 댓글