Let’s start out by doing something extremely simple. The traditional “starting point” is a “Hello world” script, so let’s start there. All we want to do is print some text, which is pretty much as simple as it seems:
- Create a new text file and name it python4mm.py.
- Add the following code:
print ("Hello, world!")
- Save the file and run the script by typing
python3 ./python4mm.pyon the command line. If you get output of
Hello, world!then you know everything is working perfectly.
Now, that was a pretty simple task, but we can already learn a whole lot from it. Let’s take a look at the syntax here:
print ("Hello world!")
Here’s what we know so far, just from this one line script:
- There aren’t any line numbers.
- When we send data to a function (such as print()) we enclose it in parentheses.
- Strings, or bits of text, get enclosed in quotation marks. (It’s a style choice; single quotes (‘) would have worked too.)
- There are no semi-colons or other line-ending marks.
- Python as an interpreted language, so we don’t have to compile the script.
- We don’t have to import anything to do basic operations.
That’s a good start from just one line! Now let’s start actually doing something and see what else we can learn.