유피 2022. 3. 18. 22:40

윤인성_혼자 공부하는 파이썬 (유튜브)

 

- 22.03.18 Update (11~13강)

 

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
### 문자열 내 변수 삽입 ###
>>> "{}년 {}월 {}일 {}요일".format(2022318,"금")
'2022년 3월 18일 금요일'
# 데이터 시각화 등, 상세 내용 보고자 할 경우, 12강 참조
 
 
### 대문자, 소문자 변경 ###
>>> "Hello".upper()
'HELLO'
>>> "Hello".lower()
'hello'
 
 
### 문자 앞뒤 공백 제거 ###
>>> "   문   자   ".strip()  
'문   자'
# lstrip() : 왼쪽 공백만 제거
# rstrip() : 오른쪽 공백만 제거
 
 
### 문자열 내 문자열 위치 검색 ###
>>> "가나다라마바사가나다".rfind("나"# 오른쪽부터 우선해서 찾음
8
>>> "가나다라마바사가나다".find("나"# 왼쪽부터 우선해서 찾음
1
>>> "가나다라마바사".find("하"# 문자열 내 찾고자 하는 변수가 없는 경우
-1
>>> "가" in "가나다라마"
True
>>> "하" in "가나다라마"
False
 
 
### 문자열 Split ###
>>> "10 20 30 40 50".split(" ")
['10''20''30''40''50'# list 형태
 
 
### 비파괴적 함수 / 파괴적 함수 ###
>>> string = "hello"
>>> print("확인:",string.upper(),string) 
확인: HELLO hello
 
 
### 비교 연산자 ###
10 == 100 # False
10 != 100 # True
10 > 100 # False
10 < 100 # True
10 >= 100 # False
10 <= 100 # True
 
True and True = True
True and False = True
False and True = False
False and False = False
 
True or True = True
True or False = True
False or True = True
False or False = False
 
>>> age = 20
>>> under_25 = age < 25
>>> under_25
True
>>> not under_25
False
cs