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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Variable Types

A
  • Integer
  • Float
  • String
  • Boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly