Python Variables Naming Rules Quiz
18 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 keyword is used to create a global variable inside a function in Python?

  • global (correct)
  • scope
  • local
  • var
  • If you want to assign names of three different fruits to variables x, y, and z in one line, what syntax would you use?

  • x, y, z = ['Apple', 'Banana', 'Cherry']
  • x, y, z = 'Apple', 'Banana', 'Cherry' (correct)
  • fruitnames = {'x': 'Apple', 'y': 'Banana', 'z': 'Cherry'}
  • fruitnames(x, y, z) = ('Apple', 'Banana', 'Cherry')
  • In Python, what is the correct keyword to make a variable belong to the global scope?

  • scope
  • global (correct)
  • globalize
  • public
  • Which data type would the variable x be when the following code is executed: x = str(5) print(type(x)) x = 20.5 print(type(x)) ?

    <p>float</p> Signup and view all the answers

    To display the sum of 5 + 10 using variables x and y in Python, what code would you write?

    <p><code>sum = x + y; print(sum)</code></p> Signup and view all the answers

    What is the correct way to assign the value of x + y to a variable called z in Python?

    <p><code>z = x + y</code></p> Signup and view all the answers

    Which of the following is a valid Python variable name?

    <p>_myVar</p> Signup and view all the answers

    What will happen if you create a variable inside a function with the same name as a global variable?

    <p>The local variable will overwrite the global variable within the function scope.</p> Signup and view all the answers

    Which of the following is true about Python variable names?

    <p>Variable names cannot be any of the Python keywords.</p> Signup and view all the answers

    What is the purpose of using the 'print()' function in Python?

    <p>To output variables.</p> Signup and view all the answers

    What type of variables are created outside of a function in Python?

    <p>Global variables</p> Signup and view all the answers

    Which of the following cannot be a valid Python variable name?

    <p>@name</p> Signup and view all the answers

    What type of operators are used with numeric values to perform common mathematical operations?

    <p>Arithmetic operators</p> Signup and view all the answers

    Which operator is used to assign values to variables in Python?

    <p>Assignment operators</p> Signup and view all the answers

    What is the main purpose of comparison operators in Python?

    <p>Comparing two values</p> Signup and view all the answers

    Which group of operators is used to combine conditional statements in Python?

    <p>Logical operators</p> Signup and view all the answers

    What do membership operators in Python verify?

    <p>The data structure membership of a value</p> Signup and view all the answers

    In Python, which operator has the highest precedence?

    <p>** (exponentiation)</p> Signup and view all the answers

    More Like This

    Python Variables and Naming Rules
    16 questions
    Python Data Types and Conventions
    36 questions
    Debugging and Variable Naming in Python
    40 questions
    Use Quizgecko on...
    Browser
    Browser