Welcome to Day 1 of my 100 Days of Python series! Today you will write your first bits of Python code!
Let's get Python installed and start programming!
To download and install Python, all we have to do is go to the official Python website, put your mouse over the "Download" button and press to download. I recommend you download Python 3.6 or later.
Once Python is downloaded, install it as you would any normal program. Leave every setting as default for optimal experience.
Important: when installing in Windows, make sure "Add Python to PATH" is enabled.
Our first Python commands
Once Python is installed (and "Add Python to PATH" has been enabled), you can execute your text console program:
- On Windows, open
cmd.exe—you can do this from the
- On OS X, open
- On Linux, open your terminal of choice.
Once this is open, don't be scared! It's a program that allows you to open other programs, all of which communicate via text. You can type
python and this will open up the Python interpreter, a program that lets you type Python commands and runs them immediately.
It will look something like this:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
>>> is a prompt, and after it you can type your Python commands. Try it out! Type
5 + 5.
>>> 5 + 5
You'll see that Python immediately runs the code you've typed, and tells you the result:
>>> 5 + 5 10
Over the next few days we're going to look at Python in much more detail. It can do so much more than just add numbers together!
An essential part of software is the ability to store it and run it multiple times. For example, if you were writing a game you'd like to be able to store the code for the game so you can run the game again and again.
That's when the Python interpreter comes a bit short! It lets you run code immediately after typing it, but the code is not saved. If you want to run the code again, you have to type it again.
Instead, we can create a file and run it using Python.
Create a file in your Desktop called
test.py. Inside it, put the following code:
name = "Rolf" print("My name is " + name)
Once you've saved it, you can once again open your text terminal and type
python test.py. You should see some
My name is Rolf printed out!
A couple words before next time: don't worry too much about understanding every little detail when programming. Think about problems, and try to see the big picture. Remember code is just a tool to solve a problem!
When you're looking at code, think logically. Everything must be obvious to the computer. If something is there and it's not clear why, tweet at us and we'll give you a hand!
You can also join our Slack channel by clicking this link. Here you'll find a community of learners, as well as live help!
I'll see you on the next one!