7 minutes read
Basic and Intermediate Python, and Data Structures

Basic and Intermediate Python, and Data Structures

It’s no surprise that many beginning coders choose to learn Python. For years now, Python has gained a reputation as one of the most versatile and easily learned programming languages out there. As Python continues to evolve to meet the growing needs of innovative new technology sectors like machine learning and data science, the rewards for becoming well-versed in Python for developers continue to grow also.

But there is a difference between knowing the basic structures of Python, and progressing to the more advanced concepts (such as data structures and data visualization) that more advanced software and machine learning applications require. Thus, it is important for beginning programmers to know the difference between basic and intermediate Python, as well as the data structures used by experienced Python programmers for more complex applications and programs.

This guide is meant for newer programmers to learn those differences, and to understand the basic concepts at each level to help set learning goals and choose the right coding classes to advance as a Python developer. Let’s take a deeper look at the Python language, and what you need to know to master the more advanced levels and help supercharge your own Python programming career and ambitions.

"Basic

Python Basics Every Developer Should Know 

Experienced programmers often point to several key elements that form a basic understanding of the Python language for any developer. These key elements include variables, control flow/conditions, looping, functions, and user input/reading a file. Let’s explore what these different terms mean, and what you need to learn to master them:

Variables 

The easiest way to understand variables is to think of them as a word that stores a value within it. In Python, you can simply define variables and assign values, which can help you create basic logic (for example, storing the number 1 within a variable called “one”). Beyond simply integers, there are other data types that can be created and stored, such as booleans (i.e. True/False), strings, float, and others.

Control Flow 

An easy way to understand the control flow is to think of conditional statements (often thought of as “If/Then” statements, as in “If X action happens, then X result occurs”). If uses an expression to evaluate to True or False, so if the result is True, the logic subsequently executes whatever command/function is included within that statement. This could be as simple as writing the code as “If true: X happens” or could be done with rules, such as “If 2>1, then execute the print code”.

Meanwhile, the “else” statement controls what happens if the “if” expression is False (i.e. if something doesn’t meet the parameters to trigger the True logic). Else works as the alternative action. There are other control flow statements (such as an “elif” statement) that can offer other logic options while coding in possible actions and results into a particular program or app.

Looping 

Looping is a method for handling iterations, or repetitive processes that would be frustrating and painful to code individually over and over again. If you hear the terms “Iterator” or managing iterations, this is handled under the umbrella of looping. Here are a few specific examples of what looping can look like in Python:

  • “While” looping: In this case, “while” the statement is True, the code inside a particular block will be executed. The while loop requires a “loop condition” and if it remains True, it will simply continue iterating.
  • “For” looping: In this case, you pass the variable “num” to the block and the “for” statement will perform the iteration for you. 

Functions 

Functions could be considered an Advanced Basic concept, since you need to be versed in the true basics above to use them effectively. Functions are pieces of code that perform specific operational tasks and can be used multiple times as needed. Functions combine different pieces of logic to return more complex results or queries to users interacting with the front-end of a Python-powered app or software program.

User Input and Reading a File 

Finally, knowing how to take inputs from the user or any file is key to actually designing an app or software program to respond quickly, efficiently, and most importantly, correctly. This includes knowing how to open, read, write, and close files while coding within Python.

Intermediate Python Concepts 

Once you have progressed past mastering the basic fundamentals above, you are ready to start learning some of the intermediate Python concepts. Similar to above, here is a short list of some of the most commonly understood “Intermediate” Python fundamentals:

Object-Oriented Programming

Object-oriented programming (often referred to in shorthand as OOP) is a programming paradigm centered on the concept of "objects", which can include both data and code. The data takes the form of fields (often referred to as attributes or properties), and code, in the form of procedures (or methods). In Python, there are some basic design patterns of OOP that intermediate programmers need to master, including how to define classes, objects, methods, and some other elements to code more complex processes into your app or software.

There are also some more advanced OOP concepts like polymorphism, data abstraction, Dunder methods, and encapsulation which offer further programming benefits, but could be considered Advanced Intermediate concepts that come after the ones noted above.

List Comprehensions 

This method allows programmers to slickly define and create lists based on existing lists in a program. This allows for more compact programming and faster operations, which can increase the speed (and thus, the user experience or UX) of a particular Python program.

Lambda Functions 

Lambda functions are quite simply small anonymous functions that you can use along with the map method to help clean up your code and keep it simple. This is essential especially if you are working as part of a programming team, where developers may need to swap spots and work on each other’s code (and thus, cleaner code reduces the time needed for explanations or detailed coding comments/notes as you write).

Inheritance 

Inheritance allows programmers to define a particular class that inherits all the methods and properties of another class (essentially, allowing you to “copy and paste” the structural elements of another class to avoid repetitive and time-consuming coding). For an easy example, if you’re creating different animal classes and require a dog class, you could simply inherit all methods and properties of a generic ‘Animal’ class into the new ‘Dog’ class. Since “Dog” will use the same set of properties, this lets you quickly add new classes that are similar.

Modules, Libraries, and PIP 

Like any open-sourced language, one of the biggest benefits of Python is the ever-expanding list of user-created libraries and modules that can be installed to perform advanced functions (and thus, save you tons of time coding the same things from scratch). PIP (PIP Installs Packages) and libraries generally exist to solve problems that previous Python developers discovered, and can perform advanced functionality to power portions of your app or software. Some of the most widely used include Requests (for sending HTTP requests), Pillow (for image processing), Selenium (for automating browsers), MoviePy (for video editing), and BeautifulSoup (for web scraping).

Data Structures

Understanding Python data structures is another essential piece to truly mastering and realizing the benefits of the language at a more advanced level. To put it simply, data structures are the fundamental constructs around which you build your programs. Each data structure provides a particular way of organizing data so it can be accessed efficiently, depending on your use case. Python ships with an extensive set of data structures included in its standard library.

Here are some of the most important data structures for you to learn:

Dictionaries, Maps, and Hash Tables 

In Python, dictionaries (or dicts for short) are a central data structure which store an arbitrary number of objects, with each object identified by a unique dictionary key. Dictionaries are also often called maps, hashmaps, lookup tables, or associative arrays. No matter which name you use, these tools allow for the efficient lookup, insertion, and deletion of any object associated with a given key. Dictionaries are used by almost every major programming language, and are one of the most essential data structures to learn no matter what you plan to build or work on.

For an easier analogy for understanding dictionaries, think of a phone book. Phone books allow you to quickly retrieve the information (phone number) associated with a given key (a person’s name). Instead of having to read a phone book front to back to find someone’s number, you can jump more or less directly to a name and look up the associated information.

Arrays 

Like dictionaries, arrays are also fundamental data structures that appear in almost every major programming language, and can be used along with a wide variety of algorithms. Arrays are composed of fixed-size data records that allow every element to be efficiently and quickly located based on its particular index. Because arrays store information in adjoining memory blocks, they are known as contiguous data structures (unlike linked data structures such as a linked list).

What do arrays do for programmers? They make it much easier and quicker to look up any element contained within an array, based on the element’s index. Python includes several array-like data structures in its standard library (and there are a variety of other user-generated ones available throughout the web).

Records, Structs, and Data Transfer Objects 

In contrast to arrays, record data structures provide a fixed number of fields, each of which can be assigned a unique name and also may have a different type. Just like the other areas, Python offers programmers several data types to choose from, which can be used to implement records, structures, and data transfer objects depending on your particular programming need or software use case. Knowing the difference between them and which is most useful for a particular programming situation is another method to master to advance as a Python developer.

Sets and Multisets 

A set refers to an unordered collection of objects that doesn’t allow duplicate elements. Sets are commonly used to quickly test a value for membership in the set, to insert or delete new values from a set, as well as to compute the union or intersection of two sets. In a proper set implementation, membership tests are expected to run in fast O(1) time. Union, intersection, difference, and subset operations should take O(n) time on average. The set implementations included in Python’s standard library follow these performance characteristics. Similar to dictionaries, sets have been created and designed specifically in Python with an eye toward making them easy to create for programmers.