Read the following Python code carefully and point out the global variables? [code]y, z = 1, 2 def f(): global x x = y+z[/code]

Nguyễn Hào

New member
Read the following Python code carefully and point out the global variables?
Code:
y, z = 1, 2
def f():
    global x
    x = y+z
A. x
B. y and z
C. x, y and z
D. Neither x, nor y, nor z
 
Answer: c
Explanation: In the code shown above, x, y and z are global variables inside the function f. y and z are global because they are not assigned in the function. x is a global variable because it is explicitly specified so in the code. Hence, x, y and z are global variables.
 

Tìm kiếm

Back
Top