Data Types in Python You Need to know at the Beginning of your Data Science Journey
This article was published as a part of the Data Science Blogathon
Introduction
What are data types?
Python has six standard Data Types:-
- Numeric
- String
- List
- Tuple
- Set
- Dictionary

Image Source: link
Let’s discuss the above data types one by one:-
Numeric Data Type:-
In Python, numeric data type represents the data that has a numeric value. The numeric value can be an integer, floating number, or even complex number. These values are defined as int, float, and complex classes in Python.
Integers – This data type is represented with the help of int class. It consists of positive or negative whole numbers (without fraction or decimal). In Python, there’s no limit to how long integer values are often.
Example:-
Python Code:
Float – This type is represented by the float class. It is a true number with floating-point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer could even be appended to specify scientific notation.
Example:-
b = 1.5 print(b, "is of type", type(b)) Output: 1.5 is of type
Complex Numbers – Complex numbers are represented by complex classes. It is specified as (real part) + (imaginary part)j, For example – 4+5j.
Example:-
c = 8+3j print(c, "is a type", type(c)) Output: (8+3j) is a type
String Data Type:-
The string is a sequence of Unicode characters. A string may be a collection of 1 or more characters put during a quotation mark, double-quote, or triple quote. It can be represented using an str class.
Example:-
string1= “Hello World” print(string1) output: Hello World
We can perform several operations in strings like Concatenation, Slicing, and Repetition.
Concatenation: It includes the operation of joining two or more strings together.
Example:-
String1 = "Hello" String2 ="World" print(String1+String2) Output: Hello World
Slicing: Slicing is a technique for extracting different parts of a string.
Example:-
String1 = "Hello" print(String1[2:4]) Output: llo
Repetition:
It means repeating a sequence of instructions a certain number of times.
Example:-
Print(String1*5) Output: HelloHelloHelloHelloHello
List Data Type:-
Example:
List1 = [3,8,7.2,"Hello"] print("List1[2] = ", List[2]) Output: List1[2] = 7.2 print("List1[1:3] = ", List[1:3]) Output: List1[1:3] = [8, 7.2]
Updating the list:- we can update the list.
List1[3] = "World" #If we print the whole list, we can see the updated list. print(List1) Output: [3, 8, 7.2, ‘World’]
Tuple Data Type:-
A tuple is defined as an ordered collection of Python objects. The only difference between tuple and list is that tuples are immutable i.e. tuples can’t be modified after it’s created. It is represented by tuple class. we can represent tuples using parentheses ( ).
Example:
Tuple = (25,10,12.5,"Hello") print("Tuple[1] = ", Tuple[1]) Output: Tuple[1] = 10 print("Tuple[0:3] =", Tuple[0:3]) Output: Tuple[0:3] = (25,10,12.5)
Set Data Type:-
A set is an unordered collection of items. Every set element is exclusive (no duplicates) and must be immutable (cannot be changed).
Example:
Set = {4,3,6.6,"Hello"} print(Set) Output: {‘Hello’, 3, 4, 6.6}
As the set is an unordered collection, indexing will be meaningless. Hence the slicing operator [ ] doesn’t work.
Set[1] = 12 Output: TypeError
Dictionary Data Type:-
In Python, Dictionary is an unordered collection of data values, which is used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, a Dictionary consists of key-value pair. Key-value is provided within the dictionary to form it more optimized. In the representation of a dictionary data type, each key-value pair during a Dictionary is separated by a colon: whereas each key’s separated by a ‘comma’.
Syntax: Key:value
Example:
Dict1 = {1:'Hello',2:5.5, 3:'World'} print(Dict1) Output: {1: ‘Hello’, 2: 5.5, 3: ‘World’}
We can retrieve the value by using the following method:
Example:
print(Dict[2]) Output: 5.5
We can update the dictionary by following methods as well:
Example:
Dict[3] = 'World' print(Dict) Output: {1: ‘Hello’, 2: 5.5, 3: ‘World’}
Conclusion
About The Author
Prashant Sharma
Currently, I Am pursuing my Bachelors of Technology( B.Tech) from Vellore Institute of Technology. I am very enthusiastic about programming and its real applications including software development, machine learning, and data science.
Hope you like the article. If you want to connect with me then you can connect on:
or for any other doubts, you can send a mail to me also
One thought on "Data Types in Python You Need to know at the Beginning of your Data Science Journey"
Programmer says: October 11, 2022 at 9:51 pm
Good morning, As i was reading this article i found an error for the following example output: String1 = "Hello" print(String1[2:4]) Output: llo The output should be: ll Best regards, Anonymous programmer