One, variable
1. Variable naming rules:
Syntax: (underscore or letter) + (any number of letters, numbers, or underscores)
such as: a123,_a123,_a123_
The variable name must begin with an underscore or letter, followed by any number of letters, numbers, or underscores. Case-sensitive, that is: name is not the same variable as name. The same is forbidden for Python keywords and reserved words.
Python keyword:
Falseclass finally is returnNoneContinue for Lambda TryTruedef fromNonlocal while and del Global notWithaselif if or yieldassert Else Import Pass Break except inch Raise
Note: In Python, variable names do not have types, but objects have; variable names are just references to objects (internally implemented as pointers)
2. Declaration and assignment of variables:
1)
Name = "123"# 1. Declare variable name# 2. Assign "123" to the variable name
2)
Name = "124= name #将name的值赋给变量name1
Second, user input
# !/usr/bin/env python # -*-coding:utf-8-*- # assigns the user input to the name variable name = Raw_input (" Enter user name:"# to print the input Print name
Python3 has discarded the raw_input function, the difference between the Row_input function in Python2 and the input function:
Row_input: If the user input is a number, the user input is still obtained as a string, such as user input 123, the value of name is the string "123"
Input: If the user enters as a number, the user input is obtained in int type, such as user input 123, then the value of name is the number 123.
Third, Process Control
The program flow is divided into three kinds of structure: Sequential structure (code top-down execution), selection structure, loop structure.
1. Sequential structure
Number = 111"print" (number)print(name)
program run order as shown in the code, top-down, output results are 111, "12".
2. Select structure
Grammar:
1) If Condition:
Execute conditional code block statement If condition is true or continue execution of subsequent code
2) If condition:
Condition1
Else
Condition2
Execute the Condition2 code if the Condition1 code is executed if the condition is established
3) If condition 1:
Condition1
Elif Condition 2:
Condition2
Else
Condition3
If condition 1 is established, execute Condition1 code, otherwise run Condition2 code if condition 2 is set up, run Condition3 code if none of the above is true.
Python Learning (III.)--Variable and process control