1 min to read
Python Variables
Variables store data of any kind in programming languages.
Python does not declare a variable.
Variable gets defined when you assign it a value for the first time.
You do not need to define types for variables. You can even change the type of values a single variable can hold.
Nomenclature
Conventions for naming
variables are:
- variable name must start with a letter or the underscore character
- variable name cannot start with a number
- variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- names are case-sensitive (boo & BOO are two different variables)
Display Variables
print statement outputs variables. We can use variables with strings using the + operator.
Numbers
In python there are 3 numeric types:
- int
- float
- complex
variables with numeric types are created when you first define them.
Types of Python object can be verified using the function type()
Complex numbers are specified with a “j” as the imaginary part
int, is a whole number, positive/negative, without decimals and of unlimited length.
Comments