Data Structures & Data Types in Python

Lesson 10/20 | Study Time: 10 Min
  • Definition: Data structure is a general computer science concept.

Its definition reads as follows on Wikipedia:

Data structure is a data organization, management, and storage format that enables efficient access and modification. 

More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.

  • On the other hand, data type is a concept specific to a programming language. In a way, it is a concrete implementation of a data structure in a particular programming language (be it Python or any other language).
  • The actual definition of what constitutes a "type" varies among programming languages. Talking about Python, there are basic data types like int, float, string etc. You can use the built-in types like list, set etc. which we will be covering in this session.
  • Calling these data types as data structures won’t be wrong because there is no major difference between the two in Python.

Data Types in Python

  • Before we proceed to discuss what data types in Python are, there are some basic questions that we would discuss. What is data?
  • Let’s say you are going to meet a friend at her office. When you go to visit her office, the security guard asks you to make an entry in the register before you enter the office. A typical entry register asks for the following information –


Visitor's nameVisitor's phone numberVisitor's addressEntry time
Karen32 000 000Leuven8:30 AM

The above information that you just provided is data.

We see that the data entry in the previous slide has different varieties:

        Some are English letters,

        Some are numerical digits, and

        There are some special characters, dash (-) and colon ( : ).

        In this example, our data is divided into 4 categories – name, phone number, address, and time.

        This categorization of data, based on its characteristics & our needs, is called data types.

          Some of the data types in python include:

          Integer: whole numbers, positive or negative numbers. Eg: 100.

          Float: Floating-point numbers are real numbers, rational or irrational. In most cases, this means numbers with decimal parts. Example: 123.45.

          String: Strings are sequences of characters, or text, enclosed in quotes. Example: "any text", “karen”.

          For further reading about operators and data types, visit: https://www.dummies.com/programming/python/python-all-in-one-for-dummies-cheat-sheet/

          For practice and different data type examples, visit: https://www.w3schools.com/python/python_datatypes.asp

          Getting the Data Type

          You can get the data type of any object by using the type( ) function:

          • Numerical Types: int (integer), float (decimal)
          • Text Type: str (string)
          • Boolean Type: bool (True or False)
          image.png

          GDPR

          When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, that blocking some types of cookies may impact your experience of the site and the services we are able to offer.