Data Structures in Python

Palash Hawee
3 min readMar 2, 2021

Data structures are simply the ways we process, design and store the data in programming language. In computer programming data structures are the specialized format using what we can store the data for the purpose of working on it using various algorithms. Choosing the right data structure makes one a good programmer. So what are the specific characteristics of a good programmer? well, a good programmer should have the following qualities:

  1. Picking right data structures
  2. Ability to choose right algorithms
  3. Writing good program which is readable and scalable
  4. Should know the three pillars of good code: a)Readable. b)Memory(Space Complexity). c)Speed(Time complexity)

Let’s talk about the three pillars of a good code in a nutshell:

Readability: When we code in any specific programming language we should concentrate on the readability of the program we are writing. We should not be much clever in using programming language, as for example we should avoid using too much conditional statements in our coding which won’t be readable to other programmers and moreover these types of coding will lead us to worst case state in Big O notation. Rather we can simply make our program much easier to read and understand to other programmers for further uses in future.

Memory(Space Complexity): It’s space of the machine. To solve a problem using programming language we need specific space in memory, we don’t want any unexpected code that fills up our memory space extra. For any algorithm memory can be used for: variables, Instructions and the execution.

Speed(Time Complexity): It’s the minimum execution time of a program. Nobody wants any program that requires much time for the execution. As a good programmer we’ve to concentrate on this topic.

The common data structures in any programming language are as follows:

  1. Arrays
  2. Stacks
  3. Queues
  4. Linked list
  5. Trees
  6. Graphs
  7. Hash Tables
  8. Tries

In Python we have also a collection of data structures they are:

  1. Int(Integer)
  2. Bool(Boolean)
  3. List(Arrays)
  4. Float
  5. str(String)
  6. Tuple
  7. Set
  8. Dictionary(Hash Tables)

Python Data Types numbers:

Integers : They are referred as “int” with no decimal point. Integers can be a positive or negative whole numbers.

Floating point numbers : They are integers with decimal points or fractional parts. They are referred as “float”.

Complex numbers : They are of the form a + bj where and b are floats and j is an imaginary number. Complex numbers are not used much in python programming

PYTHON DATA TYPES STRINGS:

Strings are sequence of characters using the syntax of either single quotes or double quotes.

•’hello’ “hello” “Today’s date”

•print (“Hello python”)

•print (“Hello \npython”)

•print (“Hello \t python”)

•len (“Hello”)

  • len (“Today’s date”)

Python 4 built-in data types:

There are four built-in data structures in python — list, tuple, dictionary and set.

  • List : List is a collection of items which is ordered and changeable. Allows for duplicate members. Example:

thislist = [“apple”, “banana”, “cherry”]
print(thislist)

  • Tuple : Tuple is a collection of items which is ordered and unchangeable. Allows for duplicate members. Example:

thistuple = (“apple”, “banana”, “cherry”)
print(thistuple)

  • Set : Set is a collection of items which is unordered and unindexed. Does not allow for duplicate members. Example:

thisset = {“apple”, “banana”, “cherry”}
print(thisset)

Dictionary: Dictionaries are used to store data values in key: value pairs. A dictionary is a collection which is ordered*, changeable and does not allow duplicates. Example:

thisdict = {
“brand”: “Ford”,
“model”: “Mustang”,
“year”: 1964
}
print(thisdict)

Python Boolean data type:

Booleans represent one of two values: True or False.

print(10 > 9)
print(10 == 9)
print(10 < 9)

print(bool(“Hello”))
print(bool(15))

Output will be only True or False.

These are the all data structures in Python programming language. Exercising these data structures we will be more capable to know which data type to use depending on the project or the purposes of our program. Thank you.

Palash Hawee

Linkedin

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Palash Hawee
Palash Hawee

No responses yet

Write a response