파이썬 배열 역순(거꾸로) 출력, reversed, slice notation
총 5개 방법으로 배열을 거꾸로(역순) 출력하는 예제 소개합니다. 파이썬 배열을 선언하고, while, range 역순, reversed, slice notation 이용합니다. ◆ 예제 소스123456789101112131415161718192021222324252627282930#-*- coding: utf-8 -*- # 배열 선언colors = ['black', 'White', 'red', 'GREEN', 'blue'] # 1. while 문i = len(colors) - 1while i >= 0: print(colors[i], end=', ') i -= 1print() # 2. range 역순 출력 1for c in range(-1, -len(colors)-1, -1): print(colors[c..
2019. 5. 14.