Python first knowledge and variables :
variable Name:-- letter -- number -- underline "see the meaning of the name"
(PS: Numbers do not start; they cannot be keywords; it is better not to repeat with Python built-in)
-- Basics :
"1" The first sentence of Python, although the suffix can be arbitrary? However, if the module is imported, there will be an error if the. py file is not.
the suffix name of the Python file is. py.
"2" Two modes of execution: Python interpreter py file path
Python enters the interpreter: real-time input and get to the execution result.
"3" Interpreter path: #!/user/bin/env python
"4" Code: #-*-coding:utf8-*-
"5" input, output (Python interpreter is interpreted from top to bottom line)
1 n=input (' Please enter user name ')2# wait forever until the user enters a value, The input value is assigned to the N,n username (n is the variable)3print(n)
"6" Comment: Single line comment #, multiline comment "" "three quotation marks
-- Conditional statement :
"1" conditional statement structure: (the code block must be indented before, the general indentation is 4 indents, that is, the TAB key)
1 if Condition:2 Print ('OK') #内部代码块 3else:4 Print('Error')
ifCondition 1:Print('1')elifCondition 2:Print('2')elifCondition 3:Print('3')Else: Print('0')
"2" If conditional statement supports nesting
"3"pass keyword , indicating that nothing is executed, directly over
1 # Pass 2 if 1==1:3 pass # do not execute any statements directly over 4 else:5 print(' I want to eat sesame seed ')
-- basic data type :
"1" string (in Python, as long as the quotation marks are strings, single quotes, double quotes, three single quotes, three double quotes)
(1) string addition: N1= "Zhou"
N2= "Yuan"
N3=n1+n2
Print (n3)
(2) string multiplication: n1= "Zy"
N2=n1*3
Print (N2)
"2" Number: age=21
(1) Add, subtract, multiply, divide, sub-square, remainder
--Whileloop :
"1" While condition: #条件不满足时跳出循环
code block
Four small examples of "2":
1 uses the while loop output 1,2,3,4,5,6,8,9,102 n= 13 while n<11 : 4 if n==7:< /span>5 pass 6 else : 7 print (n) 8 n=n+1
1 for 1-100 of all numbers and 2 i=13 s=0 4 while i<=100: 5 s=s+i 6 i=i+17 print (s)
1 output 1-100 all odd numbers in 2 n=13 While n<101: 4 Temp=n%25 if temp== 0: 6 pass 7 else : 8 print (N) 9 n=n+1
1 Beg 1-2+3-4+5 .... 99 and 2 n=1 3 s=0 4 while n<100: 5 If n%2==1: 6 s=s+n 7 else: 8 s=s-n 9 n=n+1print(s)
Python first Knowledge (base)