
本文共 4275 字,大约阅读时间需要 14 分钟。
1������������������
���1������������������
���Python������print()
������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������
print(1+2) # ������: 3
���2������������������
������������������������������������������������������������������������������������������ ' '
������������������������������������������������������������������������
���������
print('������������������������') # ������: ������������������������
���3������������������
������������������������������ "
������������������������������������������������������������������������������������������������
���������
print("Let���s go go go") # ������: Let���s go go go
���4���������������������
���������������������������������������������������������������������������������������������������������������������������������������������������
���������
print("Let���s go go go") # ������: Let���s go go go
2���������������
���������
number = 34name1 = 'kaikeba 'list_class = ['������������', '������', '������������']
3. Python���������������������������������������������
���������Python������������������������������������������������������
- ���������������List���������������Dictionary���������������Set������������
- ������������������Number���������������String������������������Tuple������������
4. Python������������
- ���������
\
��������������������������� - ������
\
������������������������������
5. Python������������
Numbers������������
int
��������������� -123, 456, 789float
������������������ 3.1415bool
���������������������True���False
String���������������
- ���������������
'
������������"
��������������������� - ������������������
+
������ - ���������������������������������������
List������������
- ������������
[]
������ - ���������������������������
- ���������������������������
Tuple������������
- ������������
()
������ - ���������������������������������������������
- ���������������������������������������
Set������������
- ������������
{}
������ - ������������������
- ���������������
Dict������������
- ������������
{}
������ - ������������������������������
- ���������
6. ������������������
f-string������������������������
- ���
f
������ - ������������������������������������
- ���������
name = '������'age = 24print(f'Hello, {name} {age}') # ������: Hello, ������ 24
at-string���@-���������������������
- ������
@
��������������������� - ���������
print(f'Hello, {name}') == f'Hello, {name}'
7. ������������
Python���������������������������������������������������������������
input()
���������������������open()
���������������write()
���������������read()
���������������������
8. ������������
������ try-except-finally
������������������������
try: with open('file.txt', 'r') as f: print(f.read())except FileNotFoundError: print('���������������')finally: print('������������������')
9. ������������
���������
class Person: def __init__(self, name, age): self.name = name self.age = age def __str__(self): return f'���������������{self.name}������������{self.age}'
���������
p1 = Person('������', 24)p1.__str__()
10.������������������
class Animal: def __init__(self): self.name = '������'class Dog(Animal): def __init__(self): super(Dog, self).__init__() self.breed = '���' def __str__(self): return f'{self.name}���������{self.breed}'
11.������������
���Python������������������������������ raise
���������
class CustomError(Exception): pass# ������������raise CustomError("������������")# ������������try: raise CustomError("������������")except CustomError as e: print(e.args)
12.������������
for������
students = ['������', '������', '������']for student in students: print(student)
while������
n = 2while n <= 3: print(n) n += 1
13.������������
������������������ def
������������������ class
���������������������������������������������������������������
14.������������������
���������������������������������������������
int()
float()
str()
list()
发表评论
最新留言
关于作者
