python模块引用
实例
python10_class.py
'''
类class
'''
# 定义类
class Student(): #括号内为空,默认继承Object类
def __init__(self,name,city): #构造函数
self.name=name
self.city=city
print("My name is %s and come from %s" %(name,city))
def talk(self):
print("Hello world,"+self.name)
python11_module.py
'''
模块module
'''
import time # 导入时间模块
import random # 导入随机数模块
from time import sleep # 导入模块中的方法
from python10_class import Student # 导入模块中的类
# 导入时间模块 显示当前系统时间
now=time.ctime()
print(now)
# 导入随机数模块 显示随机整数
number=random.randint(1,10) #显示[1,10]之间的整数
print(number)
# 休眠5秒
print(time.ctime())
sleep(5)
print(time.ctime())
#生成实例对象
stu1=Student("小明","Beijing")
stu1.talk()
stu2=Student("小王","Shanghai")
stu2.talk()