[Python] 오른쪽(right) 우선 순회
iterable 객체 오른쪽(right) 우선 순회 방법
# 스텝 슬라이싱(step slicing) 을 이용한 순회
lst = ['a','b','c','d','e','f','g']
for i in lst[::-1]:
print(i, end= ' ')
g f e d c b a
# list pop 메소드를 이용한 순회
lst = ['a','b','c','d','e','f','g']
while True:
try:
print(lst.pop(), end=' ')
except IndexError:
break
g f e d c b a
'[파이썬] 개념정리 > [파이썬] 구문,문법정리' 카테고리의 다른 글
[Python] 함수와 문자열포매팅 (0) | 2021.01.20 |
---|---|
[Python] list와 str의 슬라이싱(Slicing) (0) | 2020.07.10 |
[Python] 객체지향 문법2 (생성자와 소멸자 method) (0) | 2020.07.08 |
[Python] 객체지향 문법 (class와 object) (0) | 2020.07.08 |
[Python] try-except-else-finally (0) | 2020.07.04 |