About Python
Python is created by Guido. Van Rossum to inherit the ABC program. Python has no advantage over the speed of C and other languages, but because of its complete library of classes and simplicity, it is becoming one of the programmers ' favorite programming languages. According to the latest Tiobe charts, Python has occupied the last four, and in recent years has maintained the top five, there is a promising future.
Getting Started with Python
1. Python Installation
The latest version is Python3 and is constantly being updated. Python2 is also in use, and is constantly being updated with the direction of Python3. The specific installation operation is not explained in detail.
2, "Hello World"
1) run through the Python interpreter
Open cmd, run Python, and note the configuration of the environment variable.
C:\users\zj>Pythonpython2.7.12 | Anaconda 4.2.0 (64-bit) | (default, June 29 2016, 11:07:13) [MSC v.1500 64bit (AMD64)] on Win32type" Help","Copyright","credits" or "License" forMore information. Anaconda isbrought to Continuum analytics.please check out:http:Continuum.io/thanks andhttps://anaconda.org>>>Print('Hello World') Hello World
2) Run directly
In practice, you need to save your code in a timely manner, in the format of. py, to prevent code loss or file format confusion.
# ! /usr/bin/env python# coding=utf-8print"HelloWorld"
3. File Opening code
#! /usr/bin/env python: Interpreter path. appears primarily in Linux because the file paths in Linux are represented in addition to the full path. Not required in Windows.
# Coding=utf-8: Indicates that a character in the Python2 contains Chinese characters, and that the character can be represented by how many digits, saving space. Not required in Python3.
4. Variable, input, output
Variable rule:
1) Any combination of letters, numbers, underscores
2) The first character cannot be a number
3) Python keyword (e.g. Class,and,as ... ) cannot be a variable
4) Python built-in name, function cannot be a variable
Inputs: input, raw_input
Output: Print
Name = Raw_input (")print name
5, indentation and Process Control
The Python syntax is indented and generally indents 4 spaces, using tab.
If statement
1) Basic statement
If condition 1:
code block
Else
code block
2) Nesting mode
If condition 1:
If condition 2:
......
3) If elif
While loop
While condition:
code block (until the condition is not met)
Ps:
Continue: Exiting the current loop
Break: Exit the entire loop
6. Practice
1) use while loop input 1 2 3 4 5 6 8 9 10
num = 1 while num < one: if num! =7 :print num = num + 1
2) for all numbers of 1-100 and
num = 1= 0 while num <=: = sum +num = num + 1print sum
3) All odd numbers in the output 1-100
num = 1 while num <=: if num% 2 = = 1: Print num = num + 1
4) All even numbers in the output 1-100
num = 1 while num <=: if num% 2 = = 0: print num = num + 1
5) Seeking 1-2+3-4+5 ... 99 of all numbers of the and
num = 1= 0 while num <: if num% 2 = = 1: = sum1 + num = num + 1 else: = sum1- num = num + 1 Print sum1
6) User Login (three chance retry)
Name ="Qiuchen"Passward="123456"Num=0 whileNum < 3: Register_name= Raw_input ("User name:") Register_passward= Raw_input ("Password:") ifRegister_name = = Name andRegister_passward = =Passward:Print "Landing Success" Break Else: Num= num + 1Print "User name or password error, please try again"ifnum = = 3: Print "the number of errors is too many, please try again later"
Python full stack development for input and output and process control