Q51. What is the output of the following Python program regarding local variable shadowing?
#!/usr/bin/python ```python def fun1(a): ``` print'a:',a a=33; print'locala:',a a=100 fun1(a) print'aoutsidefun1:',a Output: a:100 locala:33 aoutsidefun1:100
Technical Question Bank · Peer-Reviewed
Search and filter frequently asked interview questions across technical, programming, and behavioral domains. Tailor your interview preparation by difficulty for freshers or experienced developers (338 available).
#!/usr/bin/python ```python def fun1(a): ``` print'a:',a a=33; print'locala:',a a=100 fun1(a) print'aoutsidefun1:',a Output: a:100 locala:33 aoutsidefun1:100
#!/usr/bin/python ```python def fun2(): ``` globalb print'b:',b b=33 print'globalb:',b b=100 fun2() print'boutsidefun2′,b Ans. Output: b:100 globalb:33 boutsidefun2:33
#!/usr/bin/python ```python def foo(x,y): ``` globala a=42 x,y=y,x b=33 b=17 c=100 print(a,b,x,y) a,b,x,y=1,15,3,4 foo(17,4) print(a,b,x,y) Ans.Output: 4217417 421534
### The Code Snippet: ```python def foo(x=[]): x.append(1) return x print(foo()) print(foo()) ``` ### Output: ```python [1] [1, 1] ``` ### Technical Explanation: In Pytho...
By specifying #!/usr/bin/pythonyou specify exactly which interpreter will be used to run the script on a particular system. This is the hardcoded path to the python inter...
### Code Snippet: ```python items = ['a', 'b', 'c', 'd', 'e'] print(items[10]) ``` ### Output: Python raises an **`IndexError`**: ``` IndexError: list index out of range ...
list=['a','b','c','d','e'] printlist[10:] Ans. Output: [] Theabovecodewilloutput[],andwillnotresultinanIndexError. As one would expect, attempting to access a member of ...
### Expression: ```python [x**2 for x in range(10) if x % 2 == 0] ``` ### What It Does: This list comprehension iterates through the numbers `0` through `9`, filters for ...
Sets and dictionaries support it. However tuples are immutable and have generators but not comprehensions. Set Comprehension: r={xforxinrange(2,101) ifnotany(x%y==0foryin...
In Python's object model, every object has a type, value, and identity. Whether its internal value can change without creating a new identity determines its mutability: #...
HireXTech uses essential storage to remember your study preferences and third-party advertising cookies via Google AdSense in compliance with GDPR. You can choose to enable essential cookies only or accept all cookies. Read our Privacy Policy.