Post

Python Developer
Python Developer@PythonDvz·
What is the output? Write your answer in the comments and share it with your friends 👑👑
Python Developer tweet media
English
14
8
77
6.9K
Jimmy Fikes
Jimmy Fikes@akajim·
@Python_Dv B. Error. The variable num is local to the fun1 function. This means it is out of scope (i.e. inaccessible) outside of that function block.
English
0
1
6
337
PyBerry Tech 🐍🍓
PyBerry Tech 🐍🍓@PyBerryTech·
@Python_Dv Option B : Error variable num is defined inside a function and it's scope is limited to fun1. Outside if we try to access num it will throw an error.
English
0
0
4
499
Jay
Jay@learnaiwthme·
@Python_Dv The answer is B: Error ✅ Why? num is only defined as a parameter inside fun1. After calling fun1(5), the returned value is not stored anywhere. Then print(num) tries to access num in the global scope, but it does not exist there. So Python raises a NameError.
English
0
0
2
153
asteroid
asteroid@earth_asteroid·
@Python_Dv Error. "num" is a local variable, so inaccesible out of the function. To print the result of the function "fun1", it should be good to change line 2 with <print(num + 25)> (without angle brackets) and delete line 5.
English
0
0
1
135
Prem Prakash
Prem Prakash@4EverPrem·
@Python_Dv Error. num is a local variable and exists only in the function fun1, therefore, when it is called outside the function, it will result in error.
English
0
0
1
140
DanTheTechMan
DanTheTechMan@dantechenth·
@Python_Dv B: NameError. Core Python scoping. Even CPython's bytecode can't touch locals outside their frame.
English
0
0
0
17
Paylaş