Python
■■■■■■■■■
Lecture Notes — ■■■■■■■■■■
■■■■■ 1.0 | 2025■■■ | ■3■
■ ■■ ■ ■■ ■ ■■■■
■■■■■■■■■■■ ■■■■■■■■■■■■■ ■ 3■5 ■■
■■
■1■ Python■■■
...... 3
1.1 Python■■■■■■
...... 3
1.2 ■■■■■■■■■■■
...... 3
1.3 ■■■■■■■■ Hello, World!
...... 4
■2■ ■■■■
...... 4
2.1 ■■■■■■■
...... 4
2.2 ■■■
...... 5
2.3 ■■■■ (if / elif / else)
...... 5
2.4 ■■■■ (for / while)
...... 6
■3■ ■■■■■■■■
...... 6
3.1 ■■■■■■■
...... 6
3.2 ■■ (dict)
...... 7
3.3 ■■■■■■■■■■
...... 7
3.4 ■■■■■■■■■■■■
...... 8
■■ ■■■■■■■■■■■
...... 8
■1■ Python■■■
1.1 Python■■■■■■
Python■1991■■Guido van Rossum■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■Web■■■■■
■■■■■■■AI/■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ ■■
■■■■■■■ ■■■■■■■■■■■■■■■■■■■■■■■
■■■■■■■■ NumPy, Pandas, Flask■■■■■■■■■■■■■■■
■■■■■■■■ ■■■■■■■■■■■■■■■■■■■■■■■■■■
■■■■■■■■■■■ Windows / macOS / Linux ■■■■■■■■■
1.2 ■■■■■■■■■■■
■■■■■■ Python 3 ■■■■■■■■■■■■■■■■■■■■■■■■■■
① [Link] ■■■■■■Python 3.x■■■■■■■■■■■■■■■■
② ■■■■■■■■■■■■■■■■■ python --version ■■■■■■■■■■■■■
③ ■■■■■■■■■VS Code, PyCharm ■■■■■■■■■■
■ VS Code ■ Python ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
1.3 ■■■■■■■■ — Hello, World!
■■■■■■■■■■■■■■■■■Hello, World!■■■■■■■■■■■
# [Link]
print("Hello, World!")
# ■■■■
# Hello, World!
print() ■■■■■■■■■■■■■■■■■■■■■■■■#■■■■■■■■■■■■■■■■■■
■2■ ■■■■
2.1 ■■■■■■■
Python■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■ ■ ■■
int 42 ■■
float 3.14 ■■■■■■
str "Python" ■■■
bool True / False ■■■
NoneType None ■■■■null■■■
name = 'Alice' # str
age = 20 # int
gpa = 3.85 # float
is_student = True # bool
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
2.2 ■■■
■■ ■■■ ■ / ■■
■■ + - * / // % ** 10 // 3 → 3 2**8 → 256
■■ == != < > <= >= 5 != 3 → True
■■ and or not True and False → False
■■ += -= *= /= x += 1 (x = x+1)
2.3 ■■■■■if / elif / else■
■■■■■■■■■■■■■■■■Python■■■■■■■■■■■■■4■■■■■■■■■■■■■
score = 75
if score >= 90:
print('S■■')
elif score >= 70:
print('A■■') # ■■■■■■■■
elif score >= 50:
print('B■■')
else:
print('■■■')
■ ■■■■■■■■■■■■■ IndentationError ■■■■■■■■■■■■■4■■■■■■■■■
2.4 ■■■■■for / while■
# for ■■■ — ■■■■■■■■■
fruits = ['apple', 'banana', 'cherry']
for fruit in fruits:
print(fruit)
# range() ■■■■■■
for i in range(5): # 0,1,2,3,4
print(i, end=' ')
# while ■■■
count = 0
while count < 3:
print('count =', count)
count += 1
■3■ ■■■■■■■■
3.1 ■■■■■■■
■■■■■■■■■mutable■■■■■■■■■■■■■■■■■■■■■■immutable■■■■
# ■■■
nums = [10, 20, 30, 40, 50]
print(nums[0]) # 10 (■■)
print(nums[-1]) # 50 (■■)
print(nums[1:3]) # [20, 30] ■■■■
[Link](60) # ■■■■■
[Link](20) # ■■■■
# ■■■■■■■■■
point = (3, 5)
x, y = point # ■■■■■
3.2 ■■■dict■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ O(1) ■■■■■■
student = {
'name': 'Alice',
'age': 20,
'gpa': 3.85
print(student['name']) # Alice
student['major'] = 'CS' # ■■■■
print([Link]('grade', 'N/A')) # ■■■■■
# ■■■■■■■■■■
for key, value in [Link]():
print(f'{key}: {value}')
3.3 ■■■■■■■■■■
def ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
def greet(name):
"""■■■■■■■■"""
return f'■■■■■■{name}■■■'
# ■■■■
message = greet('Bob')
print(message) # ■■■■■■Bob■■■
# ■■■■■■■■■■■■■■
def min_max(lst):
return min(lst), max(lst)
lo, hi = min_max([3, 1, 4, 1, 5, 9])
print(lo, hi) # 1 9
3.4 ■■■■■■■■■■■■
# ■■■■■■■
def power(base, exp=2):
return base ** exp
print(power(3)) # 9 (exp=2■■■■■■)
print(power(3, 3)) # 27
# ■■■■■■■
print(power(exp=4, base=2)) # 16
■ ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ ■■■■■■■■■■■
■■■■ ■■■■ ■■■
SyntaxError ■■■■■■■■■■■■■■■ ■■■■■■■■■■■■■■■
IndentationError ■■■■■■■■■■■■ ■■■■4■■■■■■
NameError ■■■■■■■■■ ■■■■■■■■■■■■■■
TypeError ■■■■■■■■ (str + int) int()■str()■■■■■■
IndexError ■■■■■■■■■■■ len()■■■■■■■■■■■■■■
KeyError ■■■■■■■■■■■■ [Link](key, default)■■■
ZeroDivisionError 0■■■■ ■■■■■■■0■■■■■■
■ ■■■■■■■■■ ■■■■■■■■■■■■ Python ■■■■■■■■■
■■■■■■■■■■■■■ / ■■■■ / ■■■■■■■■■■■■ / ■■■■■■■■NumPy, Pandas■