>>> abs(3) 3 >>> abs(-1.2) 1.2
>>> divmod(7, 3) (2, 1)
>>> hex(234) '0xea'
>>> int('3') 3 >>> int(3.4) 3 >>> int('1A', 16) 26
>>> oct(34) '0o42' >>> oct(12345) '0o30071'
>>> pow(3, 2) 9 >>> pow(38, -1, mod=97) 23
>>> list(range(5)) [0, 1, 2, 3, 4] >>> list(range(5, 10)) [5, 6, 7, 8, 9] >>> list(range(1, 10, 2)) [1, 3, 5, 7, 9]
>>> round(4.6) 5 >>> round(5.678, 2) 5.68
>>> sum([1,2,3]) 6 >>> sum((4,5,6)) 15
>>> chr(97) 'a' >>> chr(8364) '€'
>>> eval('1+2') 3 >>> eval("'hi' + 'a'") 'hia' >>> eval('divmod(4, 3)') (1, 1)
>>> ord('a') 97 >>> ord('0') 48
) or class str(object=b
, encoding='utf-8', errors='strict') : 입력받은 데이터를 문자열 객체로 반환>>> str(3) '3' >>> str('hi') 'hi'
>>> for i, name in enumerate(['body', 'foo', 'bar']): ... print(i, name) ... 0 body 1 foo 2 bar
>>> list("python") ['p', 'y', 't', 'h', 'o', 'n'] >>> list((1,2,3)) [1, 2, 3]
>>> sorted([3, 1, 2]) [1, 2, 3] >>> sorted(['a', 'c', 'b']) ['a', 'b', 'c'] >>> sorted("zero") ['e', 'o', 'r', 'z'] >>> sorted((3, 2, 1)) [1, 2, 3]
>>> tuple("abc") ('a', 'b', 'c') >>> tuple([1, 2, 3]) (1, 2, 3) >>> tuple((1, 2, 3)) (1, 2, 3)
>>> list(zip([1, 2, 3], [4, 5, 6])) [(1, 4), (2, 5), (3, 6)] >>> list(zip([1, 2, 3], [4, 5, 6], [7, 8, 9])) [(1, 4, 7), (2, 5, 8), (3, 6, 9)] >>> list(zip("abc", "def")) [('a', 'd'), ('b', 'e'), ('c', 'f')]
>>> all([1, 2, 3]) True >>> all([1, 2, 3, 0]) False >>> all([]) True
>>> any([1, 2, 3, 0]) True >>> any([0, ""]) False >>> any([]) False
def positive(x): return x > 0 print(list(filter(positive, [1, -3, 2, 0, -5, 6]))) 결과값: [1, 2, 6]
>>> a = 3 >>> id(3) 135072304
>>> s = input('--> ') --> Monty Python's Flying Circus >>> s "Monty Python's Flying Circus"
>>> class Person: pass ... >>> a = Person() >>> isinstance(a, Person) True
>>> len("python") 6 >>> len([1,2,3]) 3 >>> len((1, 'a')) 2
>>> def two_times(x): ... return x*2 ... >>> list(map(two_times, [1, 2, 3, 4])) [2, 4, 6, 8]
>>> max([1, 2, 3]) 3 >>> max("python") 'y'
>>> min([1, 2, 3]) 1 >>> min("python") 'h'
>>> type("abc") <class 'str'> >>> type([ ]) <class 'list'> >>> type(open("test", 'w')) <class '_io.TextIOWrapper'>