This guide will assume you are installing 3. x. x.
If you want to disable certain functions, change the installation directory, or install the debugger, click “Customize installation” instead and then check or uncheck the boxes.
If you just want to use the included version of Python, you can create scripts in a text editor and run them through the terminal.
You can also install Python using Ubuntu’s Add/Remove Applications app located in the Applications window.
Type print(“Hello, World!”) and press ↵ Enter. You should see the text Hello, World! displayed beneath the Python command line.
Python is one of the easier languages to learn, and you can have a basic program up and running in just a few minutes.
If you didn’t integrate Python into your command prompt, you will need to navigate to the Python directory in order to run the interpreter.
Unlike many other languages, you do not need to designate the end of a line with a ;. You also will not need to use curly braces ({}) to designate blocks. Instead, indenting will signify what is included in a block.
Make sure to save the file somewhere easy to access, as you will need to navigate to it in the command prompt. For this example, save the file as “hello. py”.
Depending on how you installed Python and what version it is, you may need to type python hello. py or python3 hello. py to run the program.
The sequence will run as long as (while) b is less than (<) 100. The output will be 1 1 2 3 5 8 13 21 34 55 89 The end=’ ’ command will display the output on the same line instead of putting each value on a separate line. There are a couple things to note in this simple program that are critical to creating complex programs in Python: Make note of the indentation. A : indicates that the following lines will be indented and are part of the block. In the above example, the print(b) and a, b = b, a+b are part of the while block. Properly indenting is essential in order for your program to work. Multiple variables can be defined on the same line. In the above example, a and b are both defined on the first line. If you are entering this program directly into the interpreter, you must add a blank line to the end so that the interpreter knows that the program is finished.
This will return 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
This program also introduces a few other very important statements that will be invaluable for a variety of different applications: input() - This invokes user input from the keyboard. The user will see the message written in the parentheses. In this example, the input() is surrounded by an int() function, which means all input will be treated as an integer. range() - This function can be used in a variety of ways. In this program, it is checking to see if the number in a range between 13 and 20. The end of the range is not counted in the calculation.
There are lots of good books available for Python programming, including, “Python for Beginners”, “Python Cookbook”, and “Python Programming: An Introduction to Computer Science”. There are a variety of sources available online, but many are still geared towards Python 2. X. You may need to make adjustments to any examples that they provide. If you want to run python online but wish to run python 3, Repl[1] has a python interpreter that uses virtual linux machines. Another good online resource for a future “pythonista” (well-versed python programmer) is thinkfunctional[2]. For bigger challenges, “Automate the Boring Stuff”[3] and Project Euler[4] are also available. Many local schools offer classes on Python. Oftentimes Python is taught in introductory classes as it is one of the easier languages to learn.