2017년 5월 2일 화요일

Python Basic

Python Basic

List

>>> L = range(10)
>>> L
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> L[::2]       ##odd idx selection
[0, 2, 4, 6, 8]

>>> L[1::2]     ##even idx selection
[1, 3, 5, 7, 9]

>>> 4 in L     ##memership test
True
>>>

Tuple

>>> t = (1,2,3)
>>> len(t)
3

>>> t[0:2]
(1, 2)

>>> t[::2]
(1, 3)

>>> t+t+t
(1, 2, 3, 1, 2, 3, 1, 2, 3)

>>> t*3
(1, 2, 3, 1, 2, 3, 1, 2, 3)

>>> 3 in t
True

difference between List and tuple
 - Each element of List can be changed, while tuple can't.

댓글 없음:

댓글 쓰기

Python Naming Convention

Type Option Default regular expression Argument argument-rgx [a-z_][a-z0-9_]{2,30}$ Attribute attr-rgx [a-z_][a-z0-9_]{2,30}...