Hello dear, today we will all read about the data types given in Python, so what are we waiting for, let’s start..
What is Data type in Python | Python Data Types example
Data types denote the type of data stored into variables. Like other programming languages Python has a set of built-in data types. Since everything is object in Python, every data type in Python is a class and each variable is an object of a class.
Data types classification:
|Numeric||int, float, complex|
|Sequence||list, tuple, range|
|Binary types||bytes, bytearray, memoryview|
Text is a collection of characters otherwise called as string.String is represented using str data type. A set of characters enclosed within a set of single quotes(‘) or set of double quotes(“) is called string literal.Multiline strings are enclosed within triple quotes (”’ or “””)
s='Hello world' print(s)
1 2 3
s="""Hi friends. Happy programming.""" print(s)
Hi friends. Happy programming.
Strings are immutable
String is an object that is not changeable after creation. So it is called immutable object. The contents of string objects cannot be overwritten.
1 2 3
s="""Hi friends. Happy programming.""" s='p'
Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> s='p' TypeError: 'str' object does not support item assignment
Slicing the strings
Slicing is the process of extracting a range of characters or substring from the given string.
string_name[starting index:ending index(not included)]
s="Happy programming" print(s[6:13])
Numeric data types represented using int, float and complex and are called as Python Numbers.
The numbers without fractional part (a decimal point and a set of digits after the decimal point) are called integers. The numbers 10,-100,234 are the examples of integers. Integer values can be of any length.
The limit on the length of integers is dependent on the limit of the memory in the computer.
a = 1234567890123456789 print(a)
Floating point numbers are the numbers with fractional part (a decimal point and a set of digits after the decimal point), represented by ‘float’ data type and are 64-bit double precision values in all platforms. The maximum floating point value a variable can have is 1.8*10308 .
Complex numbers are represented in the form a+bj, where a is real part and b is the imaginary part.
1 2 3 4
a=1+2j b=3+4j c=a+b print(c)
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?