02. Setting up Python

Head over the Python.org and download Python version 3.

To launch Python, simply type "python" onto your command line interface if you're on a Unix environment (Mac OS X or Linux). If you're on Windows, open Python's IDLE. You should see the version of Python 3.x.x, as shown below.

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Interactive mode

Python starts up in Interactive Mode. This means that you can type in some command and Python will interpret that query and output a response.

For example, try inputting a number. Python should output the number

>>> 123
123

Primary and Seconary prompts

Python lines will always be preceded by the primary prompt >>>. If there is an unfinished command that goes to the next line, a secondary prompt will be activated with lines preceding with ...

>>> print("Hello world!"
... )
Hello world!

Notice how a secondary prompt appeared because the parentheses was not closed.

Comments

Comments in python are preceded by a hashtag (#) to the end of the line. As long as the hashtag is not embedded within quotes, it everything proceeding it will be ignored by the interpreter.

>>> # This is a comment that won't be interpretted.
...
>>>

Zen of Python

Within your interpreter try typing import this to print out the Zen of Python. Here you can find Python's philosophy.

>>> import this

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Learn to be a Pythonista!

Introducing Python

Learn to be a Pythonista! Try Python

Easy to understand and fun to read, Introducing Python is ideal for beginning programmers as well as those new to the language. Author Bill Lubanovic takes you from the basics to more involved and varied topics, mixing tutorials with cookbook-style code recipes to explain concepts in Python 3. End-of-chapter exercises help you practice what you learned.

$ Check price
39.9939.99Amazon 4.5 logo(37+ reviews)

More Python resources

Ad