Example : How to store static/constant values and display them in Python?
x = 10
y = "India"

print("The output is = ", x)
print('The output is = ', y)

Output:
The output is =  10
The output is =  India

-----------  OR  ------------

a = 10
A = "Python is case sensitive"

print("The output is = ", a)
print('The output is = ', A)

Output:
The output is =  10
The output is =  Python is case sensitive

-----------  OR  ------------

x = "India"
y = "is"
z = "Great"
print(x, y, z)
print(x + y + z)

Output:
India is Great
IndiaisGreat

-----------  OR  ------------

x, y, z = "India", "is", "Great"   # Multiple variable declaration
print(x, y, z)

Output:
India is Great

-----------  OR  ------------

x = y = z = "India is Great"    # Single assignment into Multiple variables
print(x, y, z)

India is Great
India is Great
India is Great

-----------  OR  ------------

x = 10
y = 20
z = x + y
print("The addition result is = ", z)
print('The addition result is = ', z)
print(f"The addition result is =  {z}")

Output:
The addition result is =  30
The addition result is =  30
The addition result is =  30

-----------  OR  ------------

x = 10.52
y = 20.32
z = x + y
print("The addition result is = ", z)

Output:
  The addition result is =  30.84

-----------  OR  ------------

x = 10.52
y = 20
z = x + y
print("The addition result is = ", z)

Output:
  The addition result is =  30.52
Example : How to store dynamic/user input values and display them in Python?
x = input()
y = input()
z = int(x)+int(y)
m = float(x)+float(y)
n= str(x)+str(y)

print("The addition result is = ", z)
print(f"The addition result is =  {z}")
print("The addition result is = ", m)
print("The addition result is = ", n)

Output:
10
20
The addition result is =  30
The addition result is =  30
The addition result is =  30.0
The addition result is =  1020

-----------  OR  ------------

x = input("Enter first Integer value = ")
y = input("Enter second Integer value = ")
z = int(x)+int(y)

print("The addition result is = ", z)
print(f"The addition result is =  {z}")

Output:
Enter first Integer value = 20
Enter second Integer value = 30

The addition result is =  50
The addition result is =  50
Example : How to display the data type used by individual variables in Python?
x = 25
y = 20.35
z = "Hello India"

print(type(x))
print(type(y))
print(type(z))

Output:
<class 'int'>
<class 'float'>
<class 'str'>
Example : How to store Collections values into Individual Variables in Python?
animals = ["Tiger", "Lion", "Cat", "Dog"]
a, b, c, d = animals
print(a)
print(b)
print(c)
print(d)

Output:
Tiger
Lion
Cat
Dog
Example : What are the different types of Division in Python?
x = 15
y = 2
print(x // y) #floor division(//) rounds the result down to the nearest whole number
print(x / y)  #simple division
print(x % y)  #remainder or modulo division

Output:
7
7.5
1
Example : How do we use exponent in Python?
x = 15
y = 2
print(x ** y)

Output:
225

Some Important links:

Loading

Categories: Python Theory

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.