Python 3 Tutorial
Python is an interpreted objected oriented programming language. It is cross platform which means you can run it on Windows, Linux, and MacOS.
It is interpreted in the sense that the compiler executes the code line by line when processing the files.
Python can be used to create desktop and web applications among other things. It is usually used in Artificial Intelligence systems. Artificial Intelligence in a layman's terms is a computer system that does cool things like read your mind and predicate the future.
You login on YouTube, and watch and a couple of videos then bam! The next song you had in mind is revealed to you via the suggestions list. You buy something on Amazon and it knows that it needs to go with.
Python is totally cool for such applications. In fact, with artificial intelligence, you literally give the application the power of prophecy and you can predicate the future based on what has happened. Yes prophecy but without the belief in a supreme being and most importantly no faith is required for the prophecies. Just past data gets the job done.
Here, is all you need to know to get get started and write python applications.
- All python files end with
- To execute python files, you start with the keyword
pythonfollowed by the file name e.g.
- The simplest python application in the universe is
Yap!, that's all you need to pat yourself on the back
The following is the complete source code for a hello world application
print(...)is a built-in python function that prints out something in the terminal.
Hello Worldis the parameter that is passed to the function
...and to execute the above code you need to write the following in the terminal
- the keyword
pythonis required by universe law so is the file name
app.py. All you have to do is obey the law and all should be well in the universe.
Universal laws governing python
The following universal laws have been revealed to all followers of the great python language.
- Thou shall install python first - this goes without saying but nevertheless it must be said. You obviously need to install python to get started developing python apps. Some operating systems are both blessed and cursed, for example, its great MacOS comes with python out of the box but why the hell do they ship version 2.7? [of course as of the time that this article was written] My guess is as bad as yours. The good news is you can install the latest version which is 3.7 as of this writing.
- Thou shall install a decent Text-editor or IDE - speaking for myself, 7 years and 33 days ago I knew the difference between a text-editor and an IDE (Integrated Development Environment). Back in the good ol days, a text-editor was happy to provide syntax highlighting while an IDE did more than that. These days we have a billion plugins that can turn a text-editor into an IDE. Given am under obligation to give you the full info I have the following to say. PyCharm is a decent IDE and I know programmers who are ready to take court oaths based on it. Personally am a text-editor dude and Visual Studio Code happens to be my favorite poison, it defaults to a dark theme which is totally cool, as soon as you create a python file based on the
*.pyextension it suggests plugins to install which if you do then your text-editor turns into IDE without the heavy weight BS that comes with IDEs [am talking performance issues here]. What's not to like or taking it a step further to love about that? Share your opinions in the comments sections and I promise to personally respond to you.
- Thou shall write syntactically correct code - it can be argued that this goes without saying but i still say it. Given we are making the assumption that you are an absolute beginner then you need to know that writing code that is not syntactically correct will result into a compile error
- Thou shall Execute the code - let the record reflect the computer needs to be told everything that it needs to do (so much to tell for a machine that is supposed to be "intelligent"). The good news is the syntax is very easy. Just run
python app.pythen hit the
enterkey on the keyboard.
- Thou shall read the console output - not that there is something wrong with the south but sometimes things do go south and reading the console results gives you an idea of what on God's good terminal went south. The general expectation is that things will go north and put a smile on your face and say yess! it works.
- Thou shall code atleast 25 minutes everyday after which you reward yourself with a 5 minutes break. Do this for the next 25 days and you shall master the art of python programming. Practice for 25 minutes daily for the next 25 days and watch the magic happen. This rule is dubbed the 25/25/1 rule. I just made it up. The concept is do something for more than 25 days consistently on a daily basis and it becomes a habit, 25 minutes then hitting a 5 minutes break is just a personal productivity technique that I use to get things done (yes it works, thats how i wrote these tutorials and am only too happy you are now reading the tutorials).
Let's look at a couple of important concepts covered in this tutorial.
- Python is an interpreted language. The code is executed at runtime by the compiler line by line.
- Python can be used to create desktop or web applications among other things and application like Instagram and Dropbox have been rumored to use this particular technology.
- All python applications must end with
- A text-editor a IDE is required to write python code. How else can you do it anyway.
- Syntactically correct code is a universal python law that must be fulfilled to run the code in what can be called a pretty cool way
- To execute python code, run
python filename.pyin the console terminal.
In the next tutorial, we will assume you have installed python and a decent IDE or text-editor of your choice and then get down to coding business. As always we appreciate your comments down below. Thank you in advance.