3 Python Fundamentals – Learn How to Code in Python
This chapter is for people who have little or no experience with the Python programming language. If you already know how to use for
/while
loops, methods, and classes in Python, you can skip this chapter and you shouldn't have any problems later on.
If, however, you have not used Python before, or have only barely used it, I strongly recommend that you follow this guide. You'll learn how to code the elements of Python I mentioned in the previous paragraph, you'll fully understand the codes included in this book and you'll be able to code in Python on your own. I'll also give you some additional exercises, called "homework" throughout the chapter, which I strongly recommend that you do.
Before you begin, open your Python editor. I recommend using the Google Colab notebook, introduced to you as part of your AI Toolkit in the previous chapter. All the code, along with homework solutions, are provided on the GitHub page of this book in Chapter 3
in their corresponding section folders. Inside them, you will find two Python files: one (named the same as the section) is the code used in this book, while the homework.py
file is the solution to the exercise. Instructions for each homework exercise will be provided at the end of each section.
In this chapter, we'll cover the following topics:
- Displaying text
- Variables and operations
- Lists and arrays
if
statements and conditionsfor
andwhile
loops- Functions
- Classes and objects
Especially if you're starting from scratch, cover each section in the order they're presented here, and remember to try your hand at the homework. Let's get started!