wgz890813 发表于 2018-2-1 15:39:56

函数与过程

    小甲鱼的课程听完感觉挺简单,但是一到应用的时候,还是不能够融会贯通!在介绍完python知识点之后,再能够有一些应用的教程就好了,尤其是解决问题的思路!

函数有返回值而过程无返回值,python只有函数没有过程。返回值是python是动态的确定类型。
>>> def hello():
        print('hello,FishC')
>>> temp = hello()
hello,FishC
>>> temp
直接访问temp无任何形式,表明hello()这个函数并没有任何东西给temp
但是temp是有返回值的,python的所有函数都会返回某些东西。
>>> print(temp)
None
>>> type(temp)
<class 'NoneType'>

函数变量的作用域:局部变化(local variable)全局变量(Global variable)
def discounts(price, rate):
        finalprice = price * rate#局部变量
        return finalprice
old_price = float(input('请输入原价:'))
rate = float(input('请输入折扣率:'))#全局变量
new_price = discounts(old_price, rate)
print('打折后的价格是:',new_price)
页: [1]
查看完整版本: 函数与过程