Variables Questions and Answers

Take Exam

Python Programming - Variables Questions with Answers help understand how data is stored and referenced in Python. These Python Variables Questions are key for Infosys, Accenture, and SSC exams testing programming basics and naming conventions

Variables

Showing 10 of 24 questions

1. Which of the following is a valid variable name in Python?

  • 2var
  • _var
  • var-name
  • var name
Show Answer Report

2. What is the output of: x = 5; print(type(x))?

  • <class 'int'>
  • <class 'str'>
  • <class 'float'>
  • <class 'number'>
Show Answer Report

3. Which keyword is used to declare a variable in Python?

  • var
  • variable
  • No keyword needed
  • declare
Show Answer Report

4. What will be the value of y after: x = 10; y = x?

  • 10
  • x
  • y
  • None
Show Answer Report

5. Which of these is NOT a valid data type in Python?

  • int
  • str
  • double
  • bool
Show Answer Report

6. What does the id() function return for a variable?

  • Variable name
  • Variable value
  • Memory address
  • Data type
Show Answer Report

7. How do you swap the values of two variables in Python?

  • a, b = b, a
  • swap(a, b)
  • a = b; b = a
  • temp = a; a = b; b = temp
Show Answer Report

8. What is the scope of a variable defined inside a function?

  • Global
  • Local
  • Class
  • Module
Show Answer Report

9. Which operator is used for checking if two variables point to the same object?

  • ==
  • =
  • is
  • same
Show Answer Report

10. What is a global variable in Python?

  • Variable defined inside a function
  • Variable defined in the main program
  • Variable that cannot be changed
  • Temporary variable
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test