Local vs Global Variables in Python Quiz
3 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

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 Like This

    Python Variables Quiz
    4 questions

    Python Variables Quiz

    RevolutionaryPersonification avatar
    RevolutionaryPersonification
    Introduction to Python Programming
    16 questions
    Use Quizgecko on...
    Browser
    Browser