A variable is a name of the memory location where we store the data. For example think of box where you store all you belongings inside that box.
# Creating a bunch of variables with mixture of datatypes like int, float, boolean.
var = 20 # Integer data
var1 = 20.0 # Float data
var2 = False # Boolean data
var3 = -20 # Integer data
# Printing the variables
print(var)
print("-------------------------------------------------------------")
print(var1)
print("-------------------------------------------------------------")
print(var2)
print("-------------------------------------------------------------")
print(var3)
20 ------------------------------------------------------------- 20.0 ------------------------------------------------------------- False ------------------------------------------------------------- -20
A datatype refers to the type of data that we store inside a variable. For example we store integer datatype, float datatype and booleab datatype.
# The type of the data can be determined by using type() method.
print(type(var))
print("-------------------------------------------------------------")
print(type(var1))
print("-------------------------------------------------------------")
print(type(var2))
print("-------------------------------------------------------------")
print(type(var3))
<class 'int'> ------------------------------------------------------------- <class 'float'> ------------------------------------------------------------- <class 'bool'> ------------------------------------------------------------- <class 'int'>
Comments are very useful especially when you are stuck in understanding the code with the help of comments ypu can understand the code.Single line comments can be written by using "#" . It's a good practice to comment your code.
# This is a single line comment
Mathematical operators include additon, subtraction, multiplication, division etc. It is very easy to perform mathematical operations in python.
add = 10 + 5 # Addition
sub = 10 - 5 # Subtraction
mul = 10 * 5 # Multiplication
div = 10 / 5 # Division
exp = 10 ** 5 # Exponent
floor = 13 // 5 # Floor division
mod = 13 % 5 # Modulus operator
print(add)
print("-------------------------------------------------------------")
print(sub)
print("-------------------------------------------------------------")
print(mul)
print("-------------------------------------------------------------")
print(div)
print("-------------------------------------------------------------")
print(exp)
print("-------------------------------------------------------------")
print(floor)
print("-------------------------------------------------------------")
print(mod)
15 ------------------------------------------------------------- 5 ------------------------------------------------------------- 50 ------------------------------------------------------------- 2.0 ------------------------------------------------------------- 100000 ------------------------------------------------------------- 2 ------------------------------------------------------------- 3