With the New Year comes a new series of posts in my blog. I want to lean Python and try to document the steps as I go along. I hope this will help me better to remember all the obstacles I hit on the way. Let us see how this experiment turns out.
Motivation
I have these three reasons to learn Python and not any other language:
- It is nearly 4 years since I spend time learning a new language.
- I want to understand the Python code in the projects at work.
- Python is the most important language for machine learning.
With the blog series Python Friday, I enforce a deadline on myself so that I keep learning enough to create a blog post at the end of every workweek. I hope this will help me focus on learning and prevent me from getting too distracted along the way.
Python 2 or 3?
For a long time it looked as if the support for Python 2.x would finally end on the 1st January 2020. This date is now moved to April 2020. As far as it concerns my approach to learn Python, I will ignore Python 2 completely and only focus on Python 3.
Download and install Python
You find the official downloads at python.org/downloads/. I use Version 3.8.1 for Windows. The installer is small, but it has two things to look for. You should select the option to add Python to your PATH
:
When the installation is finished, you can select if you want to disable the path length limit. I asked Google for what this means and found this answer on StackOverflow. You have to decide for yourself if you want to disable this limit or not:
You can now open a cmd window and type this to see if everything works:
1 2 |
C:\Users\jgraber>python --version Python 3.8.1 |
At the first run this command printed 2.7.17. On my machine was already an older version of Python installed, that I had to remove first (using the add/remove software feature from Windows) until I got the expected version.
The Python Shell
Starting python without any parameter gives you the Python Shell, where you can execute Python code in an interactive environment (like irb for Ruby or the Immediate Window in the Visual Studio debugger). A HelloWorld does not need much code:
1 2 3 4 5 6 |
C:\Users\jgraber>python Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print('Hello world!') Hello world! >>> |
To not type the program over and over again, I can put the Python code into a file (Hello.py):
1 |
print("Hello World, it is 2020") |
To execute this little program I only need to call python Hello.py in the command line:
1 2 |
python Hello.py Hello World, it is 2020 |
Next
Now I have the basic setup ready to start learning the language itself. Getting at this point may look like not much, but it is the precondition for everything else. For next week, I want to find a tutorial that shows me the basic syntax of Python.
3 thoughts on “Python Friday #1: Let’s Learn Python”