Python Variable

Estimated reading: 2 minutes 662 views

python variable

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables.

				
					print("Hello World")
				
			

Assigning Values to Variables

Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.

The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. For example

				
					a = 10
b = 20
print(a)
print(b)
				
			

Multiple Assignment

Python allows you to assign a single value to several variables simultaneously. For example −

a = b = c = 1

Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example −

				
					a = b = c = 1
print(a)
print(b)
print(c)
				
			

Adding and substraction Two Value Using Level

Below is the code for addition of two value.

				
					a = 10
b = 20
get_add = a + b
get_sub = a - b
print(get_add)
print(get_sub)
				
			

Division and remainder

The Below Code demonstrate the Divison and reminder of the values.

				
					res1 = 10
res2 = 5
res3 = 6
get_div = res1 / res2
get_div_int = res1//res3
get_rem = res1%res3
				
			

And Or operators

in The and operator when all the condition are True , then output will be True.

in The or operator when any one of the condition are True , then output will be True.

 

				
					res1 = 10
res2 = 20
get_and = (res1>res2) and (res2==20)
get_or = (res1>res2) or (res2==20)
print(get_and)
print(get_or)
				
			

Comparision Operator

The Below code show the Comparision Operator

				
					a = 10
b = 20
c = 10
res1 = a >b
res2 = a >=c
res3 = b<a
res4 = c<=a
res5 = a == c
res6 = a ! = b
print(res1)
print(res2)
print(res3)
print(res4)
print(res5)
print(res6)
				
			

Leave a Comment

CONTENTS