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?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Learn to be a Pythonista!

Programming Python

Learn to be a Pythonista! Try Python

Programming Python shows in-depth tutorials on the language's number of application domains including: system administration, GUIs, the Web, networking, front-end scripting layers, and more. This book focuses on commonly used tools and libraries to give you a comprehensive understanding of Python’s many roles in practical, real-world programming.

$ Check price
64.9964.99Amazon 4 logo(56+ reviews)

More Python resources

Ad