Python (3)

This is where I will document my progress in learning Python.

One key aspect when first starting with Python is that it differs from other languages in that commands are not necessarily ending with a semicolon, and blocks are not defined by { and }. Instead, commands end where the line ends, and blocks are defined by indetation (a tab, or spaces). Example:

1) print("Hello world!")
2) print("Hello!"); print("Hello, world I mean!)

The first example above is all you need for the program to work. No semicolon is needed.
The second one, there are two commands on a single line, so a semicolon is needed to separate them.

Intendation

Intendantion is needed to form a new block. In C and many other languages, it is usually done like this:

if (x > y)
{
print("Yes, x is indeed larger than y");
}

While in Python, the same would be achieved like this:

if x > y:
print(“Yes, x is indeed larger than y”)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *