⊗pyPmFnPPP 7 of 128 menu

Passing Primitives as Function Parameters in Python

Let's look at the features of passing primitive data types (strings, numbers) to function parameters.

Let's say we have a function that takes a variable tst as a parameter and assigns it the value 2. After the function, we declare a variable num:

def func(tst): tst = 2 print(tst) num = 3

Let's call the function and pass the variable num as its parameter and print its value to the console. Even though the function parameter specifies num, its value in the global scope has not changed:

func(num) # 2 print(num) # 3

What will be the result of running the following code:

def func(txt): txt = 'user2' return txt name = 'user1' res = func(name) print(res) print(name)

What will be the result of running the following code:

def func(tst1, tst2): tst1 += 1 tst2 *= 2 return tst1 + tst2 num1 = 0 num2 = 2 res = func(num1, num2) print(num1 + num2) print(res)
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline