Quick start with Python
In this section you will write your first Python programs. Yes, we will do it right away, without theory or setting up environment (that will come later).
Our Python Project
This course is project based. We are building a simulation of Bank system and learning Python along the way. Isn't that cool? :) But for real, best learning is project based learning. This section describes what we are building within this course.
Introduction to Python (theory and environment)
This is a theoretical section. You can quickly read trough it or return back to it if you are tired of coding at any point.
Python Basics (variables, operators, input and output)
Before working on a more complex subjects we need to get our basics. Python variables, how to handle operators, strings, inputs and outputs.
Data structures in Python
Programming is all about managing data. To be able to manage data good, we need to know different ways to keep this data stored (data structures).
Code flow in Python
Programming is also abaut managing decisions. To be able to control our program, we need to learn code flow rules.
Functions in Python
Programming is all about reusing. We don't want to code same things over and over again. This is why we need functions.
Object Oriented programming in Python
Finally, it is time for us to make our banking software example. This part actually goes above "Python for Beginners", but still, try it. You might like it.
Debugging in Python
If we are to continue our programming career we will have bugs, lots of them. We need to learn how to find and fix them.
Introduction to functions in Python
Functions are named blocks of code designed to do one specific job. With functions, we write code once, and run it whenever we need to accomplish that specific task.
For example, if we create a function called open_bank_account() then:
- Whole logic for opening a bank account would be implemented inside this function.
- We would call this function whenever we need it (any time when we want to open a bank account for some customer).
Functions can take in the information they need, and return the information they generate. Using functions effectively makes your programs easier to write, read, test, and fix.
Definition/identity of a function
The first line of a function is its definition, marked by the keyword def. The name of the function is followed by a set of parentheses and a colon. The content within a function, a logic itself, is indented one level.
In this example we coded a say_hallo() function which prints “Hallo!” in console. As simple as that.
def say_hallo(): print("Hallo!") say_hallo()
There are much more use cases for functions
- Function which accepts list as an argument
- Function which modifies a list
- Function which collects an arbitrary number of arguments
- Function which collects an arbitrary number of keyword arguments
- Functions which is stored in a module
- Function imported from a module
- Function with an alias
- Selective importing of functions from a module
These topics are not covered in this lesson.
As any other programming language, Python too has a naming conventions, provided at the official Python site.
These naming conventions are not the same as in the other programming languages.
- For example, in Java or PHP, we would name functions with camel-case, where in Python we do it in small-caps separated by underscore.
- As a result, function in Java or PHP would be called openBankBalance(), but in Python will be open_bank_balance().
Let’s make one thing clear, both function names would work in all programming languages. The only difference is that Java or PHP sees openBankBalance() as pretty and clean, while Python sees open_bank_balance() as pretty and clean.
If you wonder which approach is correct? Well, both and none of them. 🙂
Simply use the convention of the programming language that you are working with.