Python is a general purpose programming language which is dynamically typed, interpreted, and known for its easy readability with great design principles.
Most *nix based operating systems come with Python installed (usually Python 2). Replacing the system Python is not recommended and may cause problems. However, different versions of Python can be safely installed along side the system Python. See Python Setup and Usage
Windows doesn’t come with Python, the installer and instructions can be found here
The Python interpreter is what is used to run Python scripts.
If it is available and in Unix shell’s search path makes it possible to start it by typing the command
python followed by the script name will invoke the interpreter and run the script.
if __name__ == '__main__' print('Hello campers!')
$ python hello_campers.py Hello campers!
"When multiple versions of Python are installed, calling them by version is possible depending on the install configuration. In the Cloud9 ide custom environment, they can be invoked like:
$ python --version Python 2.7.6 $ python3 --version Python 3.4.3 $ python3.5 --version Python 3.5.1
Interactive mode can be started by invoking the Python interpreter with the
-i flag or without any arguments.
Interactive mode has a prompt where Python commands can be entered and run:
$ python3.5 Python 3.5.1 (default, Dec 18 2015, 00:00:00) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. > print("Hello campers!") Hello campers! > 1 + 2 3 > exit() $
Some of the principles that influenced the design of Python are included as an easter egg and can be read by using the command inside Python interpreter interactive mode:
>>> import this The Zen of Python, by Tim Peters 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!
Python is well documented. These docs include tutorials, guides, references and meta information for language.
… often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.
Python also includes more powerful tools for debugging, such as:
Just note that these exist for now.
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
The built-in functions are listed in alphabetical order. The name is followed by a parenthesized list of formal parameters with optional default values. Under that is a short description of the function and its parameters are given and occasionally an example.
"Hello world!") Hello world!print(
A function is called when the name of the function is followed by
(). For the Hello world! example, the print function is called with a string as an argument for the first parameter. For the rest of the parameters the defaults are used.
The argument that we called the
str object or string, one of Python’s built-in types.
objects parameter is prefixed with a
* which indicates that the function will take an arbitrary number of arguments for that parameter.
We shall now continue with Python Basics