Python Programming by Example (2015)
1. Development Environment
Python is a widely used general-purpose, high-level programming language. Installation of Python application is easy. For Windows, Linux and Mac Platform, you download setup file from Python website, https://www.python.org/downloads/. Download and run it. Follow installation commands.
If you're working on Windows platform, you can run setup file and follow instruction.
1.2 Development Tools
Basically, you can use any text editor to write Python code. The following is a list of text editor:
· PyCharm, https://www.jetbrains.com/pycharm/
· Intellij IDEA, https://www.jetbrains.com/idea/
· Sublime text, http://www.sublimetext.com/
· Visual Studio, https://www.visualstudio.com
In this book, I use PyCharm for development tool. Jetbrains provides community and Education licenses for PyCharm.
1.3 Python Shell
After installed Python, you obtain Python shell on your platform. You can type this command on Terminal or Command Prompt for Windows Platform.
This is Python 2.x. Then, you get Python shell, shown in Figure below.
If you installed Python 3.x, you can Python shell by typing this command.
This is Python 3.x. Then, you get Python shell, shown in Figure below.
Output program on Windows platform.
After you call Python shell, you obtain the shell. It shows >>> on Terminal.
Try to do the following command.
>>> a = 3
>>> b = 5
>>> print a
>>> c = a * b
>>> print c
In Python 3.x, print a is replaced by print(a).
The following is a sample output of program.
A sample output for Windows platform.
1.4 Running Python Application from Files
You can run your program by writing them on a file. For instance, you create a file, called ch01_01.py, and write this script.
print('hello world from python')
To run the program, you can type this command on Terminal.
If you want to run the program under Python 3.x, type this command on Terminal.