函数的调用
>>> def MyFirstFunction():
print("asd")
>>> MyFirstFunction()
结果:asd
>>> def MyFirstFunction(name):
print (name + 'asd')
>>> MyFirstFunction('zxc')
结果:zxcasd
>>> def add(num1,num2):
result = num1 + num2
print(result)
>>> add(1,2)
结果:3
def test(*params):
print('参数长度是:',len(params))
print('第二个参数是:',params[1]);
>>> test(1,2,3,4,5,6,7)
结果:
参数长度是: 7
第二个参数是: 2
>>> def test(*params,exp):
print('参数长度是:',len(params),exp)
print('第二个参数是:',params[1]);
>>> test(1,2,3,4,5,6,exp=7)
结果:
参数长度是: 6 7
第二个参数是: 2
def discounts(price, rate):
final_price = price * rate
return final_price
old_price =float (input('请输入原价:'))
rate = float (input('请输入折扣率:'))
new_price = discounts(old_price,rate)
print ('打折后价格是是:',new_price)
结果:
请输入原价:100
请输入折扣率:0.5
修改后old_price的值是: 100.0
打折后价格是是: 50.0