python Download: www.python.org
python3: continuing update
python2: continuing update
Environment variable settings:
Computer Properties - Advanced - Environment Variables
Found Path, python installed in the path added to the path, separated by semicolons English format and other content
If a computer several python installation package is installed, when the execution will be run in accordance with the installation time, perform the first installation of python
You can modify the installation directory exe file name to distinguish
Output '' hello world '':
Edit text, write the following code
print('hello world')
Save with cmd execution
Python has nothing to do with the file extension, which can be txt, can be py, that is to say, it can be arbitrary file extensions
File extension appears to be arbitrary, but if when you import the module, if not .py, will be allowed to import, therefore, python file name should be saved as .py
python performed in two ways:
1.python interpreter, enter the file path to execute py
2.python, enter the interpreter, real-time input for execution
In linux code:
#! /usr/bin/env python print('hello world')
The first sentence indicates to the system python in linux where, at run time input "./.2.py" will execute python code
In python2, insert coding: utf8
# -*-coding:utf8 -*- print('hello world')
When print in Chinese, is executed successfully, otherwise it will error
But regardless of the Chinese problem python3
When the code has input, it will wait for user input values in order to enter the following program is executed
# -*- coding:utf8 -*- n=input('please input your name:') print(n)
receiving input values for n, n is a variable
Variable names can only consist of letters, numbers, underscores, but the numbers do not begin with
Keywords can not be used as variable names
The variable name is best not to repeat things and built-in python
Conditional statements:
if 条件: print('ok') else:
print('error')
if Condition 1: Results 1 elif Condition 2: Results 2 elif Condition 3: Results 3 the else : Results. 4 Print ( ' OK ' )
If you do not want to execute the statement after the if condition, use the keyword pass
if the condition: Pass the else : Print ( ' OK ' )
Basic data types:
String: content quotation marks, "***", "***", '' '***' '' '' '***' ""
Addition of the string, the string is connected speaking
Multiplication of the string, the string is repeated many times
Digital: Digital no quotes
There are digital Math
* If there are two, represents power, such as 2 ** 4, 4 th power of 2 represents
% Indicates modulo 39 7% 8 =
// represents a quotient, 8 39 // 4 =
cycle:
Endless loop
while 1==1: print('ok')
import time while 1==1: print('ok',time.time())
It does not mean a '! = 'Represents