Getting started with Python

Getting started with Python

Published at - Sep 17, 2021

>>> It means Python is ready and can install the command. The basic idea is very simple: enter the command, press Enter, enter another command, press Enter, and continue.

You probably don't know any Python commands yet. Let's see what happens when we type something and press Enter.

>>> hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined

Oops! That didn't work. But as I wrote in the introduction, error messages are our friends. This error message tells us what's wrong and where, and we'll learn what it means "the word 'hello' means later.

Maybe we can press Enter without typing anything?


That worked. How about numbers?

>>> 123
>>> -123
>>> 3.14
>>> -12.3

Wherever we go, it echoes again.

In some countries, decimal numbers are written with commas, such as 3,14 instead of 3.14. Maybe Python knows that?

>>> 3,14
(3, 14)

We did not find the error ... but (3, 14) is not what we expected! So from now on, let's use a dot with decimal numbers because 3.14 worked well. Later we will learn what it is (3, 14).


Comments are idle text when launched. They can be created by typing # and then text in the background, and they are useful when our code can be hard to understand without them.

>>> 1 + 2 # can you guess what the result is?

Again, I put a space after the # and multiple spaces before it just to make things easier to read.

If we write a comment on a line with no code on it, the prompt changes from >>> to .... To be honest, I have no idea why it does that and I think it would be better if it would just stay as >>>. The prompt goes back to >>> when we press Enter again.

>>> # hello there


Strings are small pieces of text that we can use in our programs. We can create strings by simply writing some text in quotes.

>>> 'hello'
>>> 'this is a test'
'this is a test'

Strings can also be written with "double quotes" instead of 'single quotes'. This is useful when we need to put quotes inside the string.

>>> "hello there"
'hello there'
>>> "it's sunny"
"it's sunny"

It's also possible to add single quotes and double quotes into the same string, but most of the time we don't need to do that so I'm not going to talk about it now.

It doesn't matter which quotes you use when the string doesn't need to contain any quotes. If you think that one of the quote types looks nicer than the other or you find it faster to type, go ahead and use that.

Strings can be joined together easily with + or repeated with *:

>>> "hello" + "world"
>>> "hello" * 3

Note that a # inside a string doesn't create a comment.

>>> "strings can contain # characters"
'strings can contain # characters'

Using Python as a calculator

---------- WARNING: This part contains boring math. Proceed with caution. ----------

Let's type some math stuff into Python and see what it does.

>>> 17 + 3
>>> 17 - 3
>>> 17 * 3
>>> 17 / 3

It's working, Python just calculates the result and echoes it back.

I added a space on both sides of +, -, * and /. Everything would work without those spaces too:

>>> 4 + 2 + 1
>>> 4+2+1

However, I recommend always adding the spaces because they make the code easier to read.

Things are calculated in the same order as in math. The parentheses ( and ) also work the same way.

>>> 1 + 2 * 3 # 2 * 3 is calculated first
>>> (1 + 2) * 3 # 1 + 2 is calculated first

You can also leave out spaces to show what's calculated first. Python ignores it, but our code will be easier to read for people.

>>> 1 + 2*3 # now it looks like 2*3 is calculated first

Python also supports many other kinds of calculations, but most of the time you don't need them. Actually, you don't need even these calculations most of the time, but these calculations are probably enough when you need to calculate something.


  • Error messages are our friends.
  • We can enter any Python commands to the interactive >>> prompt, and it will echo back the result.
  • +, -, * and / work in Python just like in math.
  • Pieces of text starting with a # are comments and pieces of text in quotes are strings.
  • You can use single quotes and double quotes however you want.

Related Posts -

How to Retrieve Emails Using IMAP in Python
How to Retrieve Emails Usin ...

Good day there, In a recent piece, I discussed How to use Python SMTP to se...

The Best Python Compiler to Run Code Online
The Best Python Compiler to ...

If you have Python Compiler installed on your system and want to run a prog...

Make Your Own Chrome Browser with Python PyQt5
Make Your Own Chrome Browse ...

In this step-by-step Python coding tutorial, I will show you how to create ...

How to create a screen and webcam recorder using python
How to create a screen and ...

Create a smart screen recording software like OBS studio and `Camtasia with...

Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile