Python
From YYpBD's MediaWiki
목차 |
[편집]
개요
범용 스크립트 언어이다.
[편집]
Link
[편집]
Built-in objects
[편집]
Numbers
[편집]
Strings
[편집]
Lists
[편집]
Dictionaries
[편집]
Tuples
[편집]
Files
[편집]
String Manipulation
[편집]
Baisc
>>> len('abc') # Length: number items
3
>>> 'abc' + 'def' # Concatenation: a new string
'abcdef'
>>> 'Ni!' * 4 # Repitition: like "Ni!" + "Ni!" + ...
'Ni!Ni!Ni!Ni!'
>>> myjob = "hacker"
>>> for c in myjob: print c, # Step through items.
...
h a c k e r
>>> "k" in myjob # 1 means true (found).
1
>>> "z" in myjob # 0 means false (not found).
0
[편집]
Indexing and Slicing
>>> S = 'spam'
>>> S[0], S[-2] # Indexing from front or end
('s', 'a')
>>> S[1:3], S[1:], S[:-1] # Slicing: extract section
('pa', 'pam', 'spa')
[편집]
String formatting codes
[편집]
%s
문자열 출력
[편집]
%r
문자열 자체를 그대로 출력한다.
repr()를 이용하도록 한다.
[편집]
%c
character 출력
[편집]
%d
Decimal 출력
[편집]
%i
Integer 출력
[편집]
%u
Unsigned 출력
[편집]
%o
8진수로 출력
[편집]
%x
Hex를 소문자로 출력
[편집]
%X
Hex를 대문자로 출력
[편집]
%e
부동 소수점 기수를 소문자로 표시
[편집]
%E
부동 소수점 기수를 대문자로 표시
[편집]
%f
부동 소수점 실수 표시
[편집]
%g
부동 소수점을 소문자로 표시
[편집]
%G
부동 소수점을 대문자로 표시
[편집]
%%
% 문자 출력
>>> x = 1.23456789 >>> x 1.2345678899999999 >>> '%e | %f | %g' % (x, x, x) '1.234568e+000 | 1.234568 | 1.23457'
[편집]
Anonymous Functions: lambda
표현방식일뿐 문장이 아니다.
>>> f = lambda x, y, z: x + y + z
>>> f(2, 3, 4)
9
>>> x = (lambda a="fee", b="fie", c="foe": a + b + c)
>>> x("wee")
'weefiefoe'
