
Python Fundamentals takes you from zero experience to a complete understanding of key concepts, edge cases, and using Python for real-world application development. You'll move progressively from the basics to working with larger complex applications. After completing this course, you'll have the skills you need to dive into an existing application or start your own project.
In this lesson, we will write our first Python program and play with the interpreter through the use of Python interactive shell. We will also take a look at the different ways of running a Python program. Let us cover the following topics:
An introduction to Python
Setting up and experiencing Python
Naming Identifiers
Python Syntax
Now, let us look at different features of Python, its versions, and glance through a simple Python code.
Before we begin, let’s ensure that we have Python installed on our machine. We will learn to set it up and closely experience the Python interactive shell.
Let us now write and run a simple ‘Hello World’ program. We’ll also cover writing dynamic scripts in Python.
There are different rules for naming identifiers. Let us learn about them in detail with some reserved words and practical examples. We will also get well-versed with the naming convention to write Python code.
Let us learn about the syntax of writing Python scripts in detail. In this section, we will cover the following subtopics:
Block and Inline comment
Docstrings
Indentation
Let us now summarize our learning from this lesson.
In this lesson, we’ll cover variables, values, and user input function.
Let us now look at what are variables, values, and data types.
In this section, we will look at how we can take user input from the keyboard, how to write comments, and the importance of indentation while writing Python code.
Let us now summarize our learning from this lesson.
In this lesson, we will look at other data types that are supported by Python. Data types classify data, to tell the interpreter how the program intends to utilize that data. Data types define the different operations that can be performed on the data, how the data is stored, and the meaning of the data. Let us cover the following topics:
Numerical data
Strings
Lists
Booleans
Now, let us look at different types of numbers—integers, floating point numbers, binary, hexadecimal, and octal numbers—and their representation in Python console.
Let us now understand what strings are and what different operations can be performed on a string. We’ll also cover indexing of a Python string. This section covers the following subtopics:
String definition
String Operations
Indexing
Now, as you know how strings are indexed, let us look at what more can be done with the indexed strings. This section covers the following subtopics:
Slicing
Length
In this section, let us understand strings in more detail by covering the following subtopics:
Strings are immutable
String interpolation
The str.format() method
% formatting
Let us learn the various string methods/functions available in Python along with practical examples.
This is part one of two regarding lists, which we will be going through in this course. This part will act as an introduction, and will not cover the various methods that list objects have, such as extend(), remove(), pop(), and several others. We will go through the second section on lists in a later lesson.
Finally, let us look at Booleans and the different comparison and logical operators available and their use.
Let us now summarize our learning from this lesson.
In this lesson, we are going to build on the knowledge that we have acquired so far to dive deeper into the beautiful language that is Python. We will explore how Python handles control statements—in simple terms, how Python handles decision making, for instance, resulting to True if 2 + 3 = 5. We will also dive deeper into program flow control. In particular, we will look at how we can run code repeatedly or in a loop.
Let us learn the different types of control statement. This section covers the following subtopics:
Program flow
Control statements
The if statements
The elif statements
The if…elif statements
In this section, we'll have a look at the while statement. Along with that, we'll also understand how the while statement differs from the if statement.
In Python, loops (just as in any other language) are a way to execute a specific block of code several times. Let us understand iterables and the for loop in this section.
Now, let us understand the functionality of the range function. We’ll also cover how and when to use nested loops.
Finally, let us look at how to break out of loops with practical examples of each. The following subtopics will be covered:
The break Statement
The continue Statement
The pass Statement
Let us now summarize our learning from this lesson.
In this lesson, we will build on knowledge by implementing what we have learned in the previous lesson, to build functions in Python.
Functions are an integral part of the Python programming language, and a lot of languages. Let us understand functions in more detail through these subtopics:
Functions
Built-in functions
User-defined functions
Calling a function
In this section, we’ll have a look at the local and global variables. We’ll also cover defining them through a practical example.
Most other programming languages (for example, Java and C++) require a special function, called main(), which tells the operating system what code to execute when a program is invoked. This is not necessary in Python, but in this section you will find that it is a good and logical way to structure a program.
Python supports several types of arguments, namely:
Required arguments
Keyword arguments
Default arguments
A variable number of arguments
Let us understand each one of them in detail.
This section explains anonymous functions and demonstrates how to create and use anonymous functions.
Let us now summarize our learning from this lesson.
In this lesson, we’ll delve deep into lists and tuples, right from creating and accessing to describing and implementing various methods with them.
A list is a data structure that holds ordered collections of related data. Python lists, however, are more flexible and powerful than the traditional lists of other languages. Let us understand lists in more detail through this section.
The list data type has some built-in methods that can be used with it. Let us understand their functionality.
We’ll begin this section with a demonstration on the different list methods that we saw in the previous section. We’ll also cover another feature of Python, which is a concise way to create lists—list comprehensions.
In this section we’ll cover the following subtopics:
Tuples and their properties
Tuple operations
Indexing
Slicing
Let us understand each one of them in detail.
This section explains the different tuple methods available in Python.
Let us now summarize our learning from this lesson.
In this lesson, we’ll understand the working of dictionaries and sets.
You have already seen lists that hold values that you can access by using indexes. However, what if you wanted to name each value, instead of using an index? For example, suppose that you want to access a list of cake ingredients, but you do not know where in the array it is. In that case, a dictionary would come in handy. Let us understand dictionaries in more detail.
Let us now understand the different ways of working with dictionaries such as the various methods in dictionaries and iterating through dictionaries.
This section covers the following subtopics:
Dictionary operations
Sentence analysers
Ordered dictionaries
In this section, we are going to cover sets, which are unique data structures with interesting properties. Let's begin our journey into sets by looking at how to create sets, how to read data from them, and how to remove data from them.
Let us now summarize our learning from this lesson.
At the beginning of this course, we mentioned that Python is multi-paradigm, as it supports solving problems in a functional, imperative, procedural, and object-oriented way. In this lesson, we will be diving into object-oriented programming in Python.
Let us now have a look at the following subtopics:
A first look at OOP
Defining a class and instantiating an object
Adding attributes to an object
In Python, the constructor method for an object is named __init__. As its name suggests, it is called when initializing an object of a class. Let us understand the working on the __init__ method in detail.
In this section, we’ll look at class methods in detail.
We’ll go through a practical example for the usage of methods in classes through this scenario. We’ll first look at the steps needed to perform followed by a demonstration of the solution.
We can define attributes at the class level. Class attributes are bound to the class itself and are shared by all instances as opposed to being bound to each instance. Let us understand class attributes through this section.
Now, let us test our knowledge of class attributes using this scenario. The scenario is followed by a demonstration of the solution.
Class methods differ from instance methods in that they are bound to the class itself and not the instance. As such, they don't have access to instance attributes. Additionally, they can be called through the class itself and don't require the creation of an instance of the class. Let us understand class methods through this section.
This section explains one of the key concepts of OOP—encapsulation. Encapsulation is the bundling of data with the methods that operate on that data. It's used to hide the internal state of an object by bundling together and providing methods that can get and set the object state through an interface. This hiding of the internal state of an object is what we refer to as information hiding.
We discuss another key feature of OOP in this section—inheritance. Inheritance is a mechanism that allows for a class's implementation to be derived from another class's implementation.
In this section we discuss the following subtopics:
Overriding methods,
Multiple inheritance
Mixins
Let us now summarize our learning from this lesson.
In the previous lesson, we have covered object-oriented programming in depth. We have covered important OOP concepts such as classes, methods, and inheritance. In this lesson, we will take a look at modules and file operations.
The concept of arranging work into files and folders also applies when programming in Python. You can arrange your code into pieces called modules, which makes it easier to group related functionality together. Let us have a look at how to create and use modules in Python.
This section explains the various built-in modules available in Python along with a practical example. It also covers a random generator scenario with a demonstration of the solution.
In this section, we cover packages. A package is a collection of modules. Packages are a good way of separating your modules from other people's modules to avoid name clashes.
We’ll be looking at various file operation in this section. It covers the following subtopics:
The file object
The file object methods
Reading and writing to files
Opening files
A scenario which consists of two parts, will be described in this section along with an outline of the algorithm that will be used to solve this scenario.
This section provides the solution for the first part of the scenario.
This section provides the solution for the second part of the scenario.
Now that you have a good handle on reading and writing to files, let's talk about how to deal with more structured data in this section. In real-world applications, you will most likely have to read data in a structured format.
Let us now summarize our learning from this lesson.
By now, you will have probably encountered many errors while coding in Python. This lesson aims to equip you with a better understanding of why errors occur and what to do about them when they do. This helps prevent scenarios where, for example, an error occurs on your application and because it is not handled well, brings the whole application down.
This section explains the difference between errors and exceptions. It also covers the categories of errors—logical and runtime.
Let us take a look at some common error and exception classes in this section and understand what they mean.
In this section, we will look at how to handle errors and exceptions.
Let us now summarize our learning from this lesson.
Python finds use in diverse applications, from simple desktop applications to complex scientific and numeric applications. Through this course you'll learn a language that enables you to develop applications with very few lines of code!
After a quick overview of the basics of Python, you'll get busy learning about and using variables, data types, and functions. You'll learn how to control the flow of your application by leveraging loops and control statements. You’ll also learn how to use tuples to club related information together use Lists to modify information. The later chapters teach you how to store information in dictionaries and use modules in your applications. The course concludes by showing you how to use built-in exceptions in your code to prevent your applications from crashing.
By the end of this course, you'll have the knowledge, skills, and the confidence to tackle Python projects in the real world.
About the Authors
Ryan Marvin is a software developer with extensive experience in Python. He has also worked with JavaScript and a bit of PHP. He has built web scrapers, built APIs, and worked on frontend apps using React and Angular. In his own time, he works on mobile applications and likes to contribute to open source. Currently, he is working with Andela and specializes in building smart water grid software for one of their partners.
Mark Ng'ang'a is a software developer who specializes in web technologies. He has a bachelor's degree in computer science from Jomo Kenyatta University of Agriculture and Technology, Kenya. He has been programming for 6 years in Python, PHP, and JavaScript. Mark runs a software development and consultancy fim, Builtapp Ltd., that designs, plans, and builds software solutions for diverse business needs.
Amos Omondi is a software developer, who specializes in building applications for the web. He has a bachelor's degree in computer science from Kenyatta University, Kenya. He has several years of experience working with Python, and he has dabbled in languages such as PHP, Java, C, and built products using the MEAN stack.
Sanjin Dedic is a robotics engineer. He has worked for 5 years as a Product Development Engineer and for the past 7 years, he has been teaching Digital Technologies and Systems Engineering. He has extensive classroom experience in teaching computational thinking and the foundational skills in platforms like Scratch, Arduino, Python, Raspberry Pi, and Lego Mindstorms.