LIKE A DIAMOND

python 004. 리스트 다루기b 본문

notUsed_STUDY

python 004. 리스트 다루기b

OPENLUNCH 2017. 7. 22. 21:43
728x90
반응형

#함수 range() 사용 

for value in range(1,5) :  

print(value) 


\// 5까지 출력하려면 범위를 6까지로 해야한다.



#range()로 숫자 리스트 만들기

numbers = list(range(1,6)) 

print(numbers) 


[1, 2, 3, 4, 5]  


//


squares = [] 

for value in range(1,11): 

square = value**2 

squares.append(square) 

     

print(squares) 


[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]


#숫자 리스트를 이용한 단순한 통계 (명령프롬프트이용


>>> digits = [1,2,3,4,5,6,7,8,9,0] 

>>> min(digits) 

>>> max(digits) 

>>> sum(digits) 

45 


#리스트 내포

>>> squares = [value**2 for value in range(1,11)] 

>>> print(squares) 

[1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 


#리스트일부분다루기

>>> apb = ['a', 'b', 'c' ,'d', 'e'] 

>>> print(apb[1:4]) 

['b', 'c', 'd'] 

>>> print(apb[:4]) 

['a', 'b', 'c', 'd'] 

>>> print(apb[2:]) 

['c', 'd', 'e'] 








728x90
반응형
Comments