This is an old revision of the document!
python
prepare
get python
settings
- Editors
- Visual Studio Code
- Vim
SublimetextpyCharm
$ python3 hello_world.py
variables and types
- 변수 이름은 snake_case로
- 문자열은 “This is a string”, 'This is also a string.' 모두 가능
- {string_variable}.title() → 첫 글자 대문자로
- {string_variable}.upeer()
- {string_variable}.lower()
- f-string
- full_name = f“{first_name} {last_name}”
- full_name = “{} {}”.format(fist_name, last_name)
- escape characters; \', \\, \n, \r, \t, \b, \f, \ooo, \xhh
- {string_variable}.rstrip() → 오른쪽 공백 삭제, .strip() → 양쪽 공백 제거, .lstrip() → 왼쪽 공백 제거
- numeric; integer, floating point number, underscored number → 15_000_000_000
- 상수는 대문자로; MAX_CONNECTIONS = 5000
- comments; #
message = "Hello Python" print(message)
>>> import this
list
- 중괄호 []와 ,
- 이름을 복수형으로
- 인덱스는 0부터, [-1]은 끝에서부터의 인덱스
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles)
print(bicycles[0])
print(bicycles[0].title())
bicycles[0] = 'mini bell' # change value
bicycles.append('trek') # append value
bicycles.insert(0, 'strida') # insert value
del bicycles[0] # delete
popped_bicycle = bicycles.pop() # pop value (stack)
#popped_bicycle = bicycles.pop(0) # pop value by index
bicycles.remove('redline') # remove by value
bicycles.sort() # sort permanently by alphabet
bicycles.sort(reverse=True) # reverse sort
print(sorted(bicycles)) # sort temporarily
bicycles.reverse() #
len(bicycles)