Join 36000+ teachers and students using TTIO.
Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.
x = 5
y = "TestandTrack"
A constant is a type of variable whose value cannot be changed. It is helpful to think of constants as containers that hold information which cannot be changed later. Convention in python suggests you use CAPITAL letters when declaring a constant.
PI = 3.14 GRAVITY = 9.8
x = 2 (this stores the value 2 in the variable x)
if x==2: (this checks to see if the value of x is equal to 2)
In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories:
Text: str (example: "John")
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Boolean Type: bool