The previous chapter introduces Python's knowledge, and this chapter begins with the process of creating our first Python program, first configuring the Python runtime environment.
1.python environment ready to install under 1.1.windows
Windows10
Configure environment variables to prevent program calls from making errors
"Right-click this computer"-"Properties"-"Advanced system Settings"-"Advanced" and "Environment variables"-"in the System variables bar, select the variable name path, edit"-"Append the Python installation directory to the variable value, Segmentation
For example: My path is D:\Program Files (x86) \python-362, notice that there is a semicolon in front
Upgrade installation of Python version under 1.2.linux system
Linux system is known by default Python, version is generally 2.7, it is recommended to upgrade to at least 3.5, specific content, please check my other article
Linux under upgrade Python to 3.5.2 version:
Http://www.cnblogs.com/tssc/p/7762998.html
# Python-3.6.2 Download
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
Python installation under 1.3.Mac
Similar to Linux
2. My first program: ' Hello world! ' How the 2.1.python program works
(1) Python command line runs directly (comes with the idel of the interactive device)
Enter Python in the Windows or Linux command line to enter Python command line mode.
>>>print ('Hello world! ' ) HelloWorld!
(2) written in small program, directly with Python call
Use a text editor such as Vim or notepad++ to write a helloworld.py file with the following contents:
Vim helloworld.py
Print ('Hello world! ')
Exit the text editor and enter it at the command line:
Python helloworld.py
Run helloworld.py. You can see that Python then outputs
Hello world!
(3) Specify interpreter, edit as executable script, run
You can also change the Python program helloworld.py to an executable script and execute it directly:
#!/usr/bin/env pythonprint ('Hello world! ')
Then modify the permissions to executable, directly run to see the effect
chmod 755 hello.py. /hello.py
Relevant knowledge points:
1) Print is a common function whose function is to output strings in parentheses.
2) in Python 2.x, print can also be a keyword that can be written as print ' Hello world! ', but this does not work in 3.x
3) Python does not distinguish between single and double quotes, unlike shell scripts
4) The above is a common way to run Python programs, in real development, often using the development of pycharm and other auxiliary tools for
Outreach: Hello World in other languages
1) C language
#include <stdio.h>int main (void) {printf ("\nhello world! " 0;}
2) C + +
#include <iostream>int main (void) {std::cout<<"Hello world! " ;}
3) Java language
Public class helloworld{ // Program Entry public static void Main (String args[]) { // output Information to the console System.out.println ("Hello world! " ); }}
4) PHP
<? echo"Hello world! "
5) Ruby Language
" Hello world! "
6) Go language
" FMT " Func Main () { fmt. Printf ("Hello world!\n God Bless you! " );}
# Finished, hehe
Python Journey-02. The First Python program