Python 내장 함수(Built-in Function)
1 """
2 Built-in Function
3 """
4
5 # abs()
6 print(abs(-1))
7
8 # all() bool 0 False
9 """
10 Return True if bool(x) is True for all values x in the iterable.
11 If the iterable is empty, return True.
12 """
13 print(all([0, '', None, 1, '1', 'a']))
14 print(all(''))
15
16 # any() True
17 print(any([0, '', None, 1, '1', 'a']))
18
19 # bin() 0b 0b11
20 print(bin(3))
21
22 # bool() bool 0 None '' False
23 print(bool(None))
24 print(bool(0))
25 print(bool(''))
26
27 # bytes() b
28 # utf-8 3 b'\xe4\xbd\xa0\xe5\xa5\xbd'
29 # gbk 2 b'\xc4\xe3\xba\xc3'
30 # ascii
31 # decode
32 print(bytes(' ', encoding='utf-8'))
33 print(bytes(' ', encoding='utf-8').decode('utf-8'))
34 print(bytes(' ', encoding='gbk'))
35 # print(bytes(' ', encoding='ascii'))
36
37 # chr() ASCII A a
38 # ord()
39 print(chr(65))
40 print(chr(97))
41 print(ord('a'))
42
43 # dir()
44 print(dir(all))
45
46 # divmod() ( , )
47 print(divmod(10, 3))
48
49 # eval()
50 #
51 dic = {'name': 'louis'}
52 dic_str = str(dic)
53 print(eval(dic_str))
54 print(eval('1 + 2 + 3'))
55
56 # hash() hash ,
57 # hash
58 name = 'louis'
59 print(hash(name))
60 print(hash(name))
61 name = 'scar'
62 print(hash(name))
63
64 # hex()
65 # 0x
66 # oct() 8
67 # 0o
68 print(bin(10))
69 print(hex(12))
70 print(oct(12))
71
72 # globals()
73 # locals()
74 print(globals())
75 print(locals())
76
77 # zip()
78 #
79 people = {'louis': '25', 'scar': '24'}
80 print(max(zip(people.values(), people.keys()))) # ('25', 'louis')
81 print(list(zip('abc', '123'))) # [('a', '1'), ('b', '2'), ('c', '3')]
82
83 people_dic = [{'name': 'louis', 'age': 25},
84 {'name': 'scar', 'age': 24}]
85 print(max(people_dic, key=lambda p: p['age']))
86
87 # pow() 2**3
88 # Equivalent to x**y (with two arguments) or x**y % z (with three arguments)
89 print(pow(2, 3))
90 print(pow(2, 3, 2))
91
92 # slice()
93 str_hello = 'hello'
94 s1 = slice(3, 5) # lo
95 s2 = slice(1, 4, 2) # el start stop step
96 print(str_hello[s1])
97 print(str_hello[s2])
98
99 # __import__()
100 # import 'test'
101 module_name = 'test'
102 m = __import__(module_name)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.