摘要:
1.try-except代码块 try: print(5/0)except ZeroDivisionError: print("you can't divide by zero!") 异常是使用try-except代码块处理的。try-except代码块让Python执行指定的操作,同时告诉Pyth 阅读全文
摘要:
一、读取文件 要使用文本文件中的信息,首先需要将信息读取到内存中。可以一次性读取文件的全部内容,也可以以每次一行的方式读取。 1.读取整个文件 with open('pi_digits.txt') as file_object: contents=file_object.read() print(c 阅读全文
摘要:
一、类的基本概念 class Dog(): def __init__(self,name,age): self.name=name self.age=age def sit(self): print(self.name.title()+' is now sitting.') def roll_ove 阅读全文