调用栈称为执行堆栈,运行堆栈或机器堆栈,简称堆栈。
默认情况下,无用return返回值的函数返回一个特殊值None,称为None函数。可以用于终止函数并将控制权返回给函数调用者。语法是
return 或return None
def nPrintln(message,n):
for i in range(n):
print(message)
def main():
nPrintln(n=3,message="helloworld")#关键字参数传递
nPrintln("你好,世界",3) #位置参数调用函数
#位置参数不能在关键字参数后面
#nprintln(message='世界',3)
main()
def increment(n):
n+=1
def main():
x=1
increment(x)
print(x)
main()
使用流程:
(转自https://blog.csdn.net/weixin_41441345/article/details/88225836?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task)
1.把写好的函数程序保存为.py文件并保存(复制保存路径)
2.把路径利用记事本保存为.pth文件
3.把.pth文件复制到python的安装路径→Lib→site-packages的文件夹下
(如果是Anaconda安装直接打开Anaconda→Lib→site-packages即可)
4.打开ipython import你的程序就可以愉快地使用了,记得 . A(A函数)
def printArea(i=1,j=1):
print(i,"*",j,"=",i*j)
printArea(1,2)
printArea(i=2)
printArea(j=2)
def printArea(i,j):
print(i,"*",j,"=",i*j)
def printArea(i=1,j=1,k=1):
print("Hello World")
printArea(1,2)
def f(x,y):
return x+y,x-y,x*y,x/y
t1,t2,t3,t4=f(1,2)
print(t1,t2,t3,t4)
import random
count=20
while count>0:
print(chr(random.randint(ord("a"),ord("z"))),end=" ")
count-=1