Variables Flashcards
Variables in Python
1
Q
Variables
A
Variables are symbolic names that store data or references to data.
They allow you to label and manipulate values in your programs.
2
Q
Rules for Naming Variables:
A
Must start with a letter or underscore (_).
Cannot start with a number.
Can contain letters, numbers, and underscores.
Case-sensitive (e.g., myVar and myvar are different).
3
Q
Variable Types
A
- Integer
- Float
- String
- Boolean
4
Q
Scope of Variables
A
Global Variables: Defined outside of all functions and accessible throughout the program.
Local Variables: Defined within a function and accessible only inside that function.
Nonlocal Variables: Used in nested functions to refer to a variable in the enclosing (non-global) scope.