共计 539 个字符,预计需要花费 2 分钟才能阅读完成。
#encoding:utf-8
def say_hello():
print('num1,,,,,,,')
return'fanhuizhi'
#reture 之后的代码不会执行
print('num2,,,,,,,')
say_hello()
#传参
def say_who(name,age):
print('nishi: %s, ageshi:%d' %(name,age))
#say_why(name = 'cccc', 20) 前一个参数使用了 keyword,后面也必须使用
say_who('aaaa',12)
say_who(age = 18,name = 'bbbbb')
say_who('cccc',age = 20)
#默认值 不传参数会使用默认值
def who(name,age = 28):
print('nishi: %s, ageshi:%d' %(name,age))
who('abc')
who('abc',10)
#阶乘
def cheng(number):
if number == 0:
print(1)
elif number > 0:
count = 1
for i inrange(1,number+1):
count *= i
print('%s 的阶乘为:%s'%(number,count))
else:
print('负数没有阶乘')
cheng(6)
正文完