-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter08_01.py
More file actions
98 lines (70 loc) · 2.36 KB
/
chapter08_01.py
File metadata and controls
98 lines (70 loc) · 2.36 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Chapter08-1
# 파이썬 내장(Built-in) 함수
# 자주 사용하는 함수 위주로 실습
# 사용하다보면 자연스럽게 숙달
# str(), int(), tuple() 형변환 이미 학습
# 절대값을 구해주는 함수
# abs()
print(abs(-3))
# all : iterable 요소 검사(참, 거짓)
# all은 and조건이다.
print(all([1,2,3])) # --> True
print(all([1,2,0])) # --> False
print(all([1,2,''])) # --> False
# any는 or조건이다.
print(any([1,2,3])) # --> True
print(any([1,2,0])) # --> True
print(any([1,2,''])) # --> True
# chr : 아스키 -> 문자 , ord : 문자 -> 아스키
print(chr(67))
print(ord('C'))
# enumerate : 인덱스 + Iterable 객체 생성
for i, name in enumerate(['abc', 'bcd', 'efg']):
print(i, name)
# filter : 반복가능한 객체 요소를 지정한 함수 조건에 맞는 값 추출
def conv_pos(x):
return abs(x) > 2
print(list(filter(conv_pos, [1, -3, 2, 0, -5, 6])))
print(list(filter(lambda x: abs(x) > 2, [1, -3, 2, 0, -5, 6])))
# id : 객체의 주소값(레퍼런스) 반환
print(id(int(5)))
print(id(4))
# len : 요소의 길이 반환
print(len('abcdefg'))
print(len([1,2,3,4,5,6,7]))
# max, min : 최대값, 최소값
print(max([1,2,3]))
print(max('python study'))
print(min([1,2,3]))
print(min('python study'))
# map : 반복가능한 객체 요소를 지정한 함수 실행 후 추출
def conv_abs(x):
return abs(x)
print(list(map(conv_abs,[1,-3,2,0,-5,6])))
print(list(map(lambda x:abs(x),[1,-3,2,0,-5,6])))
# pow : 제곱값 반환
print(pow(2,10))
# range : 반복가능한 객체(Iterable) 반환
print(range(1,10,2))
print(list(range(1,10,2)))
print(list(range(0,-15,-1)))
# round : 반올림
print(round(6.5781, 2))
print(round(5.6))
# sorted : 반복가능한 객체(Iterable) 정렬 후 반환
print(sorted([6,7,4,3,1,2]))
a = sorted([6,7,4,3,1,2])
print(a)
print(sorted(['p','y','t','h','o','n']))
# sum : 반복가능한 객체(Iterable) 합 반환
print(sum([6,7,8,9,10]))
print(sum(range(1,101)))
# type : 자료형 확인
print(type(3)) # --> int
print(type({})) # --> dictionary(key와 value로 구성)/ set(key와 value가 없다)
print(type(())) # --> tuple
print(type([])) # --> list
# zip : 반복가능한 객체(Iterable)의 요소를 묶어서 반환
# zip함수는 tuple로 짝을 만들어서 반환한다
print(list(zip([10,20,30],[40,50,777])))
print(type(list(zip([10,20,30],[40,50,777]))[0]))