2. Data Types
In this document you will understand, the concept of data and and how python has categorized them.
Let's ask ourselves the very first and obvious question
What is Data?
The answer to this question is really very simple. Whatever you see around you is a kind of data. For example: 1. Number of likes you get in your profile picture on Facebook/Instagram 2. The number of people you are traveling with in a train. 3. The number of members in your family/class/office.
If we go a bit professionally and overview an industry like banking, retail, e-commerce, manufacturing, logistics, etc.
An E-commerce company holds a great amount of data, like its customers' data (name, phone number, address, email id, card details, etc), product data (product id, name, brand, price, quantity, weight), transactional data (order date, delivery date, payment mode), shipping data (processing, shipped, delivered) etc.
Now, the next thing you need to ask yourself is: Is all the data the same? The Answer is NO because the name is written in alphabetical order, the phone number is in digits, and the email ID is a combination of letters, digits, and special characters.
In the same way, Python categorizes data into multiple types.
Let's understand them one by one
What is a Data Type?
In programming, a data type is a property of data based on which a computer understands what kind of operations can be performed. Unlike other programming languages, Python is a dynamically typed language; hence, we do not need to define the type of the data while giving it to the computer.
Python provides various standard data types that define the storage method and kind of operations to perform on each of them. The data types defined in Python are given below.
Standard Data Types
Numbers: Integer (int) & Float (float)
Strings (str)
Boolean (bool)
Others: List / Set / Tuple / Dictionary
Let's Start
Integer: Any whole number (positive/negative/zero) is called an Integer. The point values are not allowed. These values are denoted by 'int'. Ex: 1,2,3,4,-1,-2,-5,-56,12345,-678,0,903 etc
Float: Any number (positive/negative/zero) value with a point value is called a float. Point value is compulsory. These values are denoted by 'float'. Ex: -12.67, 0.0, 0.01,-34.78,1.0,2.35,3.14,-56.89,-0.053
String: Any character (symbol) or collection of characters (symbol) inside quotes(' '/ " "/ ''' ''') is called a string. The quotes are compulsory. Symbols can be anything. These values are denoted by 'str'. Ex: '1' , '123+45', '-678', " 45.78", 'abc123','@#$%', 'ayush', 'abhi.mishra-123@gmail.com'
Boolean: Either a True or a False value is called a Boolean. Only True and False are allowed. These values are denoted by 'bool'. Ex: True , False
Others (List / Set / Tuple / Dictionary ): These are advanced data types that will be covered in detail later.
type()
In simple words, we can say that it tells the type of data that is present between the brackets.
type(123)
# Output No output will generateBut to check the data type of a data, you need to print the result too, as it only checks the type of data, but does not show it to you because that's not its job.
print(type(123))
print(type(12.34))
print(type('Ayush Mishra'))
print(type(True))
print(type('False'))
print(type('Ayush@12345'))
# Output
# <class 'int'>
# <class 'float'>
# <class 'str'>
# <class 'bool'>
# <class 'str'>
# <class 'str'>Last updated