List Comprehension

RigidBody·2023년 4월 7일
0

Python

목록 보기
1/2
post-thumbnail

Python에서 List내에 for문을 삽입하여, 즉 lsit 내포를 사용하여 간결하게 list를 생성할 수 있다.

>>>> list_a = [n * n for n in range(1, 10) if n < 5] 
>>>> print(list_a)
>>>> [1, 4, 9, 16]
profile
Speed Enthusiast

0개의 댓글