1.try except 语句 (179:22)
避免因一些错误导致的程序崩溃
- try:
- age = int (input("Age:"))
- income = 20000
- risk = income / age
- print(age)
- except ZeroDivisionError:
- print('Age cannot be 0.')
- except ValueError:
- print('Invalid value')
- >>Age: 0
Age cannot be 0.
- >>Age: afef
- Invalid value
2.calss 类的定义 (187:46)
- class Point:
- def move(self):
- print('move')
- def draw(self):
- print('draw')
- >>point.move
- move
3. 继承 (197:59)
- class Mammal:
- def walk(self):
- print('walk')
- class Dog:
- pass# 不定义一个空类
- class Cat:
- pass
使代码简洁 不重复定义
来源: http://www.bubuko.com/infodetail-3359700.html