2017년 5월 4일 목요일

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}$
Class class-rgx [A-Z_][a-zA-Z0-9]+$
Constant const-rgx (([A-Z_][A-Z0-9_]*)|(__.*__))$
Function function-rgx [a-z_][a-z0-9_]{2,30}$
Method method-rgx [a-z_][a-z0-9_]{2,30}$
Module module-rgx (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
Variable variable-rgx [a-z_][a-z0-9_]{2,30}$
Variable, inline1 inlinevar-rgx [A-Za-z_][A-Za-z0-9_]*$

1. Used as part of list comprehensions and generators.

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}...