python worksheet 3
python worksheet 3
Example:
name = "John"
age = 25
salary = 25800.60
print(name)
print(age)
print(salary)
1. Number
Integer variable
The int is a data type that returns integer type values (signed integers); they are
also called ints or integers.
Example:
age = 28
print(age)
print(type(age))
Float variable
Floats are the values with the decimal point dividing the integer and the fractional
parts of the number. Use float data type to store decimal values.
Example:
salary = 10800.55
print(salary)
print(type(salary))
Complex type
The complex is the numbers that come with the real and imaginary part. A
complex number is in the form of a+bj, where a and b contain integers or floating-
point values.
a = 3 + 5j
print(a)
print(type(a))
String variable
In Python, a string is a set of characters represented in quotation marks. Python
allows us to define a string in either pair of single or double quotation marks. For
example, to store a person’s name we can use a string type.
str = 'PYnative'
print(str)
Get the data type of variable
No matter what is stored in a variable (object), a variable can be any type
like int, float, str, list, tuple, dict, etc. There is a built-in function called type() to get
the data type of any variable.
Example:
a = 100
print(type(a))
b = 100.568
print(type(b))
str1 = "PYnative"
print(type(str1))