⊗pyPmFnGVS 2 of 128 menu

Global scope of variables in Python

If we move the variable num from the function to the outer code block, it will acquire global visibility and will become accessible not only inside the function, but also outside:

num = 1 def func(): print(num) func() # 1

What will be the result of running the following code:

num = 2 def func(): return num func() print(num)

What will be the result of running the following code:

num = 2 def func(): return num1 print(func())
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