__init__.py
的模塊。
需要注意的是:建立函數(shù)的時候,要明白return返回不一定是像函數(shù)那章節(jié)說的那樣一定后面要跟一個什么,在這兒模塊內(nèi)函數(shù)return后面什么都不放,在調(diào)用的時候再傳遞參數(shù)。
2.1
"""
建立模塊
1.新建一個文件`fuction1.py`
2.把下面代碼放進(jìn)去
!/usr/bin/python
Filename: fuction1.py
"""
def hello1():
num_one = int(input("請輸入乘法表:"))
num_two = 1
while num_two <= 5:
num_result = num_one * num_two
print("%r×%r=%r" % (num_one, num_two, num_result))
num_two = num_two + 1
while num_one >= 0:
num_one = int(input("請輸入乘法表:"))
num_two = 1
while num_two <= 5:
num_result = num_one * num_two
print("%r×%r=%r" % (num_one, num_two, num_result))
num_two = num_two + 1
return
"""
調(diào)用模塊
1.新建一個文件`mode.py`
2.把下面代碼放進(jìn)去
3.運行
!/usr/bin/python
Filename: mode.py
"""
import fuction1 #先調(diào)用模塊: import語句 模塊名稱
fuction1.hello1() #然后調(diào)用函數(shù): 模塊名稱.函數(shù)名
2.2
"""
!/usr/bin/python
Filename: fuction2.py
"""
def hello2(b,c):
a=b+c
print(a)
return
"""
!/usr/bin/python
Filename: mode.py
"""
import fuction2
fuction2.hello2(50,5)
2.3
"""
!/usr/bin/python
Filename: fuction3.py
"""
def hello3(name):
print("hello",name)
return
"""
#!/usr/bin/python
## Filename: mode.py
"""
import fuction3
fuction3.hello3("zhangzexiang")
更多建議: