Tuesday, June 12, 2018

Variable Types in Python 3

What is Variable

Variable reserved memory location to store value 

The Python interpreter allocates memory and decides how much memory reserved based on the data types 

Data types can be store as Integers, decimals or characters 

Assigning values to variables

Do not need to declare data type at the time of variable declaration .

Python automatically declare data type when a value is assign to the variable.

The equal sign ( = ) is used to assign value to variables.

Left operator is the name of variable and Right Operator is the value stored in the variable

For Example:

StudentMark = 98     # An integer type

StudentCgpa = 9.90   # float type

StudentName = “John Doe”  # String type

# Now Print value

print(StudentMark) #
Output 98 

#Output 9.90

#Output John Doe 

Multiple Assignment

Python allows you to assign several variables at once


a = b = c = 5

#Output: 5

#Output : 5

#Output: 5

as well as you can assign multiple object to multiple variables.

For Example:

a, b, c = 1, 2.0, “John Doe”

print( a, b, c) # Output: 1 2.0 John Deo

Prev: Print Function , Indentation, Comment

Next: Data type in Python

No comments:

Post a Comment

Google+ Followers