Python Data Types - Part 1

Python data types
Python has the following built-in data types: -
Python Numbers
Integers, Floating point numbers, and complex numbers are coming
under python numbers category. For every data, types python has shortened
keyword for each of them just like int
for integer, float
for floating-point numbers
and complex
for complex numbers.
You can get the data type
of any object by using type()
function
var = 10
print(var,"is a",type(var),"of data type")
var = 10.0
print(var,"is a",type(var),"of data type")
var = 2 + 3j
print(var,"is a",type(var),"of data type")
OUTPUT
10 is a <class 'int'> of data type
10.0 is a <class 'float'> of data type
(2+3j) is a <class 'complex'> of data type
One question is raised what the program does?
So, the answer is we simply assigning the value to var three times at first we assign an int type of data and then print it to with the print function similarly, at second time and third time we assign float and complex type of data respectively.
Python integers are of any length however it is only limited
by the memory available.
Floating-point numbers could not exceed up to 15 decimal
points.
We can represent complex numbers in the form of a + ib, where a is a real part, and b is an imaginary number.
Python Strings
Strings are the one of most popular data types in python. We can
create string enclosing characters in a single quote and double quote. Python treats a single quote the same as a double quote. Creating a string is as simple as assigning a value to variables.
Note: - Multi-line strings can be represented by triple quotes.
var = "This is string"
print(var)
var = 'This is also string'
print(var)
var = '''This is a
multiline string'''
print(var)
OUTPUT
This is string
This is also string
This is a
multiline string
Post a Comment
Post a Comment
if you have any doubts, please let me know