-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathbuilt-in-functions_tutorial.py
66 lines (52 loc) · 1.6 KB
/
built-in-functions_tutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Built-in Functions
# ref. https://docs.python.org/3.6/library/functions.html
if __name__ == "__main__":
a = list(range(10))
print(a)
'''
ref. https://docs.python.org/3.6/library/functions.html#all
Return True if all elements of the iterable are true (or if the iterable is empty)
'''
print('all(a)', all(a))
print('all([])', all([])) # all([]) returns True
'''
ref. https://docs.python.org/3.6/library/functions.html#any
Return True if any element of the iterable is true. If the iterable is empty, return False.
'''
print('any(a)', any(a))
print('any([])', any([])) # any([]) returns False
'''
ref. https://docs.python.org/3.6/library/functions.html#zip
Make an iterator that aggregates elements from each of the iterables.
'''
x = [1, 2, 3]
y = [4, 5, 6]
zipped = zip(x, y)
print(list(zipped))
'''
ref. https://docs.python.org/3.6/library/functions.html#sum
'''
print('sum(a)', sum(a))
'''
ref. https://docs.python.org/3.6/library/functions.html#max
'''
print('max(a)', max(a))
my_dict = {2: 1, 3: 0}
# dict get max key
print('dict get max key:', max(my_dict))
# dict get max value
print('dict get max value:', max(my_dict, key=my_dict.get))
'''
ref. https://docs.python.org/3.6/library/functions.html#min
'''
print('min(a)', min(a))
'''
ref. https://docs.python.org/3/library/functions.html#ord
'''
print(ord('a'))
print(ord('D'))
'''
ref. https://docs.python.org/3/library/functions.html#ord
'''
print(chr(97))
print(chr(100))