Podcast
Questions and Answers
What is the difference between a local and a global variable in Python?
What is the difference between a local and a global variable in Python?
- Local variables are defined within classes and can only be accessed within that class, while global variables are defined outside of classes and can be accessed from anywhere in the program.
- Local variables are defined within functions and can only be accessed within that function, while global variables are defined outside of functions and can be accessed from anywhere in the program. (correct)
- Local and global variables are the same thing in Python.
- Global variables are defined within functions and can only be accessed within that function, while local variables are defined outside of functions and can be accessed from anywhere in the program.
What is the result of the following expression? x = 2 y = x + 1 z = y * x print(z)
What is the result of the following expression? x = 2 y = x + 1 z = y * x print(z)
- 5
- 8 (correct)
- 6
- 9
Which of the following is a valid way to compare two strings in Python?
Which of the following is a valid way to compare two strings in Python?
- string1 .= string2
- string1 = string2
- string1 < string2
- string1 == string2 (correct)