Just started to learn python, to organize their own learning sentiment
Just beginning to learn python, the code of the road is just beginning to feel the first gap. Python's punctuation is different from other languages, and it has no ";" at the back of each sentence.
Naming rules for variables
1. To have descriptive
2. Variable name can only _, number, letter composition, can not be a space or special characters (#?<.,¥$*!~)
3. Cannot use Chinese as variable name
4. Cannot start with a number
5. Reserved characters cannot be used
Constant: Unchanged amount of pie = 3.141592653 ....
All variables in the PY are mutable, so the variable names are all capitalized to represent the secondary variables as constants.
Comments
Single-line comment with #
Multiline comment with three single quotes or three double quotation marks ' ' annotated content '
Expression If ... else statement
Indent indentationerror:expected an indented block # # # # #此错误为没有缩进 ^
Indentationerror:unindent does not match no outer indentation level
tab! = 4 spaces, the indentation level must be consistent # # #假如使用了tab键进行缩进, then the indentation must all use the TAB key to indent, the official requires the use of 4 spaces.
And, and
Only if two conditions are all true (correct), the result will be true (correct)
Ex: Condition 1 and Condition 2
5>3 and 6<2 True
For and if the first condition in front is false, then the expression of the two conditions of the and before and after will be calculated as false, and the second condition will not be computed
or OR, or
As long as there is a condition of true, the result is ture,
Ex:5>3 or 6<2 True
For or, if the first condition above is true, then the result of an expression consisting of or before or after two conditions must be true, and the second condition will not be computed
Not do not take counter
Loop loops
Limited cycle, frequency limit
Infinite loop = Dead loop
Continue end this cycle, continue the next cycle
Break jumps out of the entire current loop
While loop: Executes a statement in a loop when the condition is true
While condition:
Print ("any")
Print ("any")
Guess the age of the Little program
Age = 50
#user_input_age = Int (input ("Age is:"))
#flag = True
# break
While True:
user_input_age = Int (input ("Age is:"))
if user_input_age = = Age:
Print ("Yes")
Break
Elif user_input_age > Age:
Print ("is bigger")
Else
Print ("is smaller")
Print ("End")
For Loop applet
#_author: Five Star 12138
#date: 2017/8/23
_user = "BCB"
_password = "bai199537"
Passed_authtication = False
For I in range (3):
Username = input ("Username:")
Password = input ("Password:")
If username = = _user and Password = = _password:
Print ("Welcome%s login"% _user)
Passed_authtication = True
Break
Else
Print ("Invalid username or password")
Else
Print ("Too many logins") #只要for循环正常结束完毕就会执行else, i.e. no break
# if Passed_authtication = = False:
# print ("Too many logins")
Data operations
Initial knowledge of the data type
Digital
integers int (integer)
Integral type
Long integer type
In Py3 has no distinction between integral type and long integer type, unity is called integral type
In C int age, long
There are only 2 states of Boolean, namely
True True
False false
String
Salary.isdigit ()
Everything is an object in a computer.
All things in the world are objects, all objects can be classified
Character formatted output: by placeholder
Placeholder%s s = string
%d d = digit integer
%f f = Float floating-point number, approximately equal to decimal
Format Output applet:
#_author: Five Star 12138
#date: 2017/8/23
Name = input ("Name:")
Age = Input ("Age:")
Sex = input ("Sex:")
Salary = input ("Salary:")
If Salary.isdigit ():
salary = Int (salary)
# Else:
# exit ("must be Digt")
msg = "" "------info of%s
name:%s
age:%s
sex:%s
salary:%d
""% (name,name,age,sex,salary)
Print (msg)
This article is from the "11316806" blog, please be sure to keep this source http://11326806.blog.51cto.com/11316806/1959114
The beginner's path to Python--basic knowledge