Python is more than just a programming language. It includes additional components which all work together as a holistic system. This course provides an introduction to some of these different components. Including the programming language itself. With the goal of introducing you to the Python programming language as a means of creating and controlling objects.
Upon completing this course you’ll be familiar with the basic concepts of language syntax, the python interpreter, and code blocks.
This course was designed for first-time developers wanting to learn Python. Existing developers may want to skip.
This is an introductory course and doesn’t require any prior programming knowledge. However, conceptual knowledge of Python objects is recommended.
The purpose of the Python programming language is to create and control objects. In this lesson, we’ll review how the Python language creates and controls objects.
Let’s recap what we know so far about objects.
- Objects are a means of modeling real world and abstract concepts.
- They’re Python’s low level building block.
- An object’s type is the name of the concept being modeled.
- We model concepts by extracting meaningful attributes and methods.
Python is an application written in the C programming language. When the Python application is started up it starts the Python runtime. The Python runtime consists of different components working together to create and control objects.
One of the components inside the runtime is the interpreter. I want you to think of the interpreter as a living being who speaks one language. And that language has to be spoken very precisely or else the interpreter won’t understand what you’re saying.
The language the interpreter understands is the Python programming language. The interpreter is responsible for reading Python code, interpreting its instructions, and carrying out those instructions.
The Python interpreter is designed to be able to convert Python code into actions; such as creating an object, performing an operation on an object; calling a method; etc…
The Python programming language creates and controls objects through the interpreter. We provide the interpreter with code. And that code instructs the interpreter to interact with objects in some way.
Let’s talk more about these instructions.
The interpreter includes a set of rules which define how Python code should be structured. When reading code it compares the code against the rules and determines if the code is valid. If the code is valid then the interpreter attempts to follow the instructions. Otherwise the interpreter raises an error. Because it doesn’t understand the instructions.
Programming languages have rules that the language must follow; just the same as spoken languages have rules.
These rules are referred to as syntax. And just as spoken languages are created with symbols such as letters, programming languages also have a set of allowed symbols. For Python those symbols are called keywords.
Python consists of roughly 30 to 40 keywords. These are words which have special meaning to the interpreter.
When writing Python code you’ll use:
- These different keywords.
- Your own names for certain objects.
- As well as some different symbols such as parenthesis, colons, square braces, etc.
Different actions will require the use of different combinations of these keywords, names, and symbols. The language includes keywords and syntax rules for performing different types of actions.
Action such as:
- Making decisions based on certain conditions.
- Creating objects
- Performing operations on objects
- Repeating operations
- Creating new object types
The code required to perform each of these types of actions is kind of like a template. You can almost picture the Python syntax to be like a set of templates. Where each template is used for a specific action.
Part of these conceptual templates include keywords; they include names for types, attributes, and methods; they also include symbols which have special meaning to Python.
By putting the correct pieces in the correct places - we get valid Python code.
So, we know that Python code has some set of rules that it must follow. However, how do we create Python code?
Python code is just text saved into a file with a file extension of dot py. It can be written with any text editor. That includes something as basic as notepad all the way through more developer focused options such as VS Code. I’ll introduce text editors in another lesson.
For now just know that they’re applications used to write text without including the type of behind-the-scenes formatting that applications such as Microsoft Word or Google docs include. If the interpreter was to encounter any of the formatting characters - it wouldn’t understand what to do. It would result in syntax errors.
The interpreter is responsible for reading the .py file from top to bottom, and from left to right, and determining what to do for each line of code.
If the interpreter considers the line of code to be valid Python syntax then it attempts to carry out the instruction.
So, how do we provide code to the interpreter?
There are two common ways. The most common way to send code to the interpreter is to write the code in a file with a dot py extension. Then we run the python application on the command line and specify the dot py file.
The interpreter will read through the file from top to bottom and carry out the instructions as it encounters them.
The other way is to run the python application without providing a file. This opens up an interactive console that we can type Python code into and see the results.
There’s a lot to learn when getting started with a programming language. Especially if it’s your first programming language. Many first time learners feel that they need to memorize every last bit of syntax.
Here’s my advice to you as you begin to learn the syntax for performing different tasks in Python.
Don’t feel the need to memorize Python’s syntax. The syntax solidifies in your mind the more you use it. It’s like speaking another language, it takes practice to get the structure right. For now, it's more important to understand the purpose of the language, and how it accomplishes its purpose.
Okay, this seems like a natural stopping point. Here are your key takeaways for this lesson:
- The purpose of the Python programming language is to create and control objects.
- A language's rules are referred to as syntax.
- The purpose of the interpreter is to read each line of code and interpret its meaning and return any results.
Alright, that's all for this lesson. Thanks so much for watching. And I’ll see you in another lesson!
Ben Lambert is a software engineer and was previously the lead author for DevOps and Microsoft Azure training content at Cloud Academy. His courses and learning paths covered Cloud Ecosystem technologies such as DC/OS, configuration management tools, and containers. As a software engineer, Ben’s experience includes building highly available web and mobile apps. When he’s not building software, he’s hiking, camping, or creating video games.