Comments

Comments can be added to computer programs. A comment is human readable text that is not executed by Python.

Python has several possibilities to add comments.

Single line comments

Single line comments can be added using the numbersign:

# Show the world a message
print('Hello World')

Mutliline comments

If you want to add stories or a few sentences, Python offers two ways:

# Calculate the sum of x+y
# Used in calculator app
z = x + y

Another accepted method is:

'''
We can type multiple lines of commment
if we use the indicator. 
'''

Math operations

Python has support for both mathematical operations and functions.

Mathematical operations
An overview of operations:

Operation Result
x + y sum of x and y.
x * y multiplication of x and y.
x – y difference of x and y.
x / y division of x by y.
x % y remainder of x/y
x ** y x to the power of y
abs(x) absolute value of x
sqrt(x) square root of x

Mathematical functions
Python supports a wide variety of mathematical functions.

Function Returns Example
abs(x) Returns the absolute value of x.
x = -35
x = abs(x)
print(x)
cmp(x,y) Returns -1 if x < y
Returns 0 if x equals to y
Returns 1 if x > y.
x = 6
y = 4
print( cmp(x,y) )
exp(x) Returns the exponential of x
import math
x = 6
print( math.exp(x) )
log(x) The natural logarithm of x
import math
x = 6
print( math.log(x) )
log10(x) The base-10 logarithm of x
import math
x = 6
print( math.log10(x) )
pow(x,y) The result of x**y
import math
x = 6
print( math.pow(x,2) )
sqrt(x) The square root of x
import math
x = 6
print( math.sqrt(x) )
Tip
You can use the Python interpreter as calculator. To do so you simply start Python without an IDE and filename. Example:

  Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 18*17
306
>>> 2**4
16
>>> 
  

Python IDEs

Install a Python IDE

An Integrated Desktop Environment (IDE) is a software application for programming. In addition to simple text editing they have all kind of features such as syntax highlighting, code completion, tabs, a class browser and many more.

Online Python Interpreters

The online interpreters may not work for everything but will work for most of the beginner tutorials. I recommend using a desktop IDE or the official Python interpreter.

Overview of IDEs (You only need one)

IDE Author Platform Description Price Download
PyCharm Jetbrains Windows, Mac OS X, Linux/UNIX Python IDE. Features including: code completion, code inspections, on-the-fly error highlighting and quick-fixes € 89 / 1st year.($ 97.90) Download PyCharm 
Atom (+script plugin) GitHub Windows, Mac OS X, Linux/UNIX Python IDE. You need to download the script plugin after installing Atom. Free. Download Atom.
Pythonista omz:software Apple iOS (iPhone, iPad) Features include: Syntax highlighting, code completion, interactive prompt, standard and iOS modules. € 9. ($ 9.90) Download Pythonista.
Eclipse with PyDev Aleks Totic Windows, Mac OS X, Linux/UNIX Features include: Syntax highlighting, code refactoring, graphical debugging and more. Free Download 
Eric Python IDE Detlev Offenbach Windows, Linux/UNIX Features include: Syntax highlighting, autocompletion, class browser and more. Free Download 
Wing IDE Wingware Windows, Mac OS X, Linux/UNIX Features: Syntax highlighting, auto completion, refactoring, unit testing and version control. $45 to $245 per user / license. Download 
Komodo IDE Komodo Windows, Mac OS X, Linux/UNIX Features: Syntax highlighting, documentation browser, run code in-line, quick bookmarks and more. € 40 to € 223. ($99 to $295). Download 
Skulpt Skulpt Web Python interpreter Free Run Online 
Repl.it Amjad Masad, Haya Odeh, Faris Masad and Max Shawabkeh. Web Python interpreter Free Run Online 
Ideone Ideone Web Python interpreter Free Run Online 
Codepad Steven Hazel Web Python interpreter Free Run Online