代码块一:
def hello():
print('hello1')
print('hello2')
print('hello3')
hello()
def qiuhe():
num1 = 20
num2 = 30
result = num1 + num2
print('%d + %d = %d' %(num1,num2,result))
qiuhe()
def python():
print('python')
def westos():
print('westos')
westos()
python()
def hello(a):
print('hello',a)
hello('laoli')
hello('laowu')
代码块:
#位置参数
def studentInfo(name,age): ##安装位置传参
print(name,age)
studentInfo('westos',12)
studentInfo(12,'westos')
studentInfo(age=11,name='westos')
代码块:
默认参数
def mypow(x,y=2):
print(x**y)
mypow(2,3)
mypow(4,3)
代码块一:
#可变参数
def mysum(*a):
sum = 0
for item in a:
sum += item
print(sum)
# a = [1,2,3,4,5]
mysum(1,2,3,4,5)
代码块:
#关键字参数
def studentInfo(name,age,**kwargs):
print(name,age)
print(kwargs)
print(studentInfo('westos','18',gender='female',hobbies=['coding','running']))
代码块:
def mypow(x,y=2):
return x ** y,x + y
print('hello')
print(mypow(3))
a,b = mypow(3)
print(a,b)
代码块:
a = 1
print('out: ',id(a))
def fun():
# global a
a = 5
print('in: ',id(a))
fun()
print(a)
print(id(a))