日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python调用带参函数_Python | 带有示例的函数调用类型

發布時間:2023/12/1 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python调用带参函数_Python | 带有示例的函数调用类型 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python調用帶參函數

There are following types of function calls in python:

python中有以下類型的函數調用:

  • Call by value

    按價值致電

  • Call by reference

    通過參考電話

  • 1)按價值致電 (1) Call by value )

    When, we call a function with the values i.e. pass the variables (not their references), the values of the passing arguments cannot be changes inside the function.

    當我們調用帶有值的函數時,即傳遞變量(而不是它們的引用)時,傳遞的參數的值不能在函數內部更改。

    # call by value def change(data):data=45print("Inside Function :",data)def main():data=20print("Before Calling :",data)change(data)print("After Calling :", data)if __name__=="__main__":main()

    Output

    輸出量

    Before Calling : 20 Inside Function : 45 After Calling : 20

    2)致電查詢 (2) Call by reference)

    When, we call a function with the reference/object, the values of the passing arguments can be changes inside the function.

    當我們調用帶有引用/對象的函數時,可以在函數內部更改傳遞參數的值。

    Example 1: Calling function by passing the object to the class

    示例1:通過將對象傳遞給類來調用函數

    class mydata:def __init__(self):self.__data=0def setdata(self,value):self.__data=valuedef getdata(self):return self.__datadef change(data):data.setdata(45)print("Inside Function :",data.getdata())def main():data=mydata()data.setdata(20)print("Before Calling :",data.getdata())change(data)print("After Calling :", data.getdata())if __name__=="__main__":main()

    Output

    輸出量

    Before Calling : 20 Inside Function : 45 After Calling : 45

    Example 2: Calling function by passing the reference to the list

    示例2:通過將引用傳遞給列表來調用函數

    def change(data):data[1]=25print("Inside Function :",data)def main():data=[10,20,30,40,50]print("Before Calling :",data)change(data)print("After Calling :", data)if __name__=="__main__":main()

    Output

    輸出量

    Before Calling : [10, 20, 30, 40, 50] Inside Function : [10, 25, 30, 40, 50] After Calling : [10, 25, 30, 40, 50]

    翻譯自: https://www.includehelp.com/python/types-of-function-calling-with-examples.aspx

    python調用帶參函數

    創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

    總結

    以上是生活随笔為你收集整理的python调用带参函数_Python | 带有示例的函数调用类型的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。