Local vs Global Variables in Python Quiz
3 Questions
1 Views

Local vs Global Variables in Python Quiz

Created by
@ThoughtfulTropicalRainforest

Questions and Answers

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)

  • 5
  • 8 (correct)
  • 6
  • 9
  • Which of the following is a valid way to compare two strings in Python?

  • string1 .= string2
  • string1 = string2
  • string1 < string2
  • string1 == string2 (correct)
  • More Quizzes Like This

    Python Variables Quiz
    4 questions

    Python Variables Quiz

    RevolutionaryPersonification avatar
    RevolutionaryPersonification
    Variables in Python
    8 questions

    Variables in Python

    ProgressiveChlorine avatar
    ProgressiveChlorine
    Use Quizgecko on...
    Browser
    Browser