# 包含一个学生类
# 一个sayhello函数
# 一个打印语句
# 以下模块称为p01.py
class Student():
def __init__(self,name="NoName",age=18):
self.name = name
self.age = age
def say(self):
print("My name is {0}".format(self.name))
def sayHello():
print("Hi,欢迎来到图灵学院")
print("我是模块p01呀,你可以叫我01.")
方法一
import p01
stu = p01.Student("xiaojing",19)
stu.say()
p01.sayHello()
方法二
import p01 as p# 把p01.py模块导入并作为p.py模块
stu = p.Student("yueyue",18)
stu.say()
方法三
# 有选择性导入
from p01 import Student,sayHello
stu = Student()
stu.say()
sayHello()
方法四
from p01 import *# 导入模块p01.py中所有内容都导入
sayHello()
stu = Student("yaoon",28)
stu.say()