1 Day
. A program needs
consume a large amount of manpower and material resources to do the job
after for programming, hands free, improve production efficiency
two programming languages.
Language: interpersonal communication bridge
programming language: a bridge between man and computer , who sent over some instructions to the computer programming language,
let the computer help people accomplish a job
three programming languages classification
machine language: when the computer first appeared, send instructions to the computer, the machine language
advantages: fast execution speed
Cons: print hello when you write the code is not very easy to
assembly language: a number of relatively simple machine language instructions by various English characters
advantages: fast execution speed
Cons: learning costs and low efficiency of the code written in
high-level language: print world the Hello!
Print ( 'hello world!')
advantages: write and learn easy
disadvantages: execution speed is slower
compiled language: compile once run everywhere (performed on the file to another computer can also be used)
C language, C ++, Java
interpreted language: edge execution side translation (Python \ PHP code is translated by the interpreter to execute computer )
PHP, Python (written in C is based on the bottom)
interpreted language compiler-based language
four .Python introduction
blog to build: hexo or open a blog on cnblog
founder of Python: turtle t (in Amsterdam, 1989)
Python version: python2.7 and Python3.7 (python.org official website to download)
Python coexistence of multiple versions:
1. Enter installation directory, type: Python3 or Python 2, into the command interface (command + r open cmd, input folder address)
2. configure the environment variable:
step: my computer ---> properties ---> advanced system settings ---> --- environment variables> system variables path, on behalf of the python installation path inside.
Five .Pycharm use
use Pycharm, professional writing Python code, will code syntax checking
Pycharm shortcut keys:
Ctrl + D: copy a whole line
ctrl + Z: Undo the duplicate
shift + arrow keys to select representatives to do a
ctrl + shift + F10: Code run fast
shift + enter: wrap
ctrl + ?: line comment
ctrl + shift + ?: block comments
question 1: settings-inter compiler can not use the 3.7 and 2.7
Notes and retracted six .Python
# or single line comment
'' 'multi-line comment' ''
retracted: indention affiliation, i.e. generally agreed four spaces a tab represents one indentation (indentation there can be formed affiliation, the same indention on the same level)
if True: print(123) print(456)
String plus a newline \
Seven variables.
Example: Price: The value of the variable
cherries: the name of the variable
to store the price of cherries: memory (local storage variable value)
price types: numeric types (floating point, integer)
type of the variable:
1 The digital type
float float (decimal): 90.89,89.9
integer int (integer): 90,100
Boolean (BOOL): True, False
2. string str type:
Mono quoted string is relatively short: 'abgsoidjga '; "agabgasfa"
triple quotes:' '' can be a long string content newline '' '
variable definition rules:
any combination of 1 letters, numbers or underscores the
first character of the variable name can not be 2. digital
3. the following key words can not be declared as variable names: and, as, assert, break and so on
eight strings.
string concatenation
+: string on spliced, it is the sum integer
s1 = 'hello' s2 = 'world' print(s1+s2) s3 = 3 s4 = 4 print(s3+s4)
Use placeholder character for% s
#my name is stephen, age is 18, height is 180 %代表格式化的效果 name = 'stephen' age = 18 heigth = 180 print("my name is %s, age is %s, height is %s" %(name, age, height))
In list using [xxx, xxx, xxx]
by name integers, floats, and strings are stored for all classes
is represented by [], the value of which may be any type
# 0123 index stus = [ ' zhangsan ' , ' Lisi ' , ' LXX ' , ' Stephen ' ] Print (stus [2]) # output LXX Li = [12 is, 34 is, 45, ' HelloWorld ' , [ 1,2,3,4 ]] Print (Li [. 4] [2]) # output 3
Using the dictionary dict
# statement: can put any data type declared by {}, {}, the composition of the key and the value
info = { "name" : "zhangsan", "age" : 18, "height": 180 "xxxx" : ["agag",'agar',12] } print(info['xxxx'][0]) #agag
Tuple ()
s = ('xxxx', '111') print(s[0])
Nine operational expression.
1. Math:
% modulus (remainder)
** # a power of 2 3 = 8 **
2 ** square root (1/2) 2
// take the integer part # divisible // 4 = 2 9
2. Comparative arithmetic
True or False
enable connection ratio: 20 is> A> 10
3. assignment operator
chain assignment | cross assignment | decompression assignment | pressurized assignment
chain assignment
a = b = c = 10
Print (A, B, C)
crossing assigned
a ^ = b XOR exchange
100 = A B = 200 A, B = B, A # to the right (200, 100) is assigned to the left = 200 A, 100 B = Print (A, B)
Or with c, a + b; before adding to a container, after calculating the sum of
the pressing assignment
A =. 1, 2,. 3
Print (A) # (. 1, 2,. 3) assigned to the three values of a, a tuple format
decompression assignment: the number of the variable is assigned a certain number of the number of decompression obtained consistent
strings and lists, dict like may store a plurality of data may be decompressed
A = (. 1, 2,. 3) # with a value of the received representative of the overall assignment Print (A) A, B, C = (. 1, 2,. 3 ) Print (A, C) A, B, C = ' ABC ' # get the corresponding string Print (a, C)
4. logical operations
and not or: short circuit
to 10 with interaction:. If-else
example
# authentication username and password
# If the error, output error
# right, output welcome
s = input ( "Enter Username:") # make input
print (s) # promise out background
print (s, type (name) ) # type string type has been entered str
select the else-IF #
IF expression:
executing code
else:
executing code
= the INPUT name ( ' Please enter your user name: ' ) pwd = the INPUT ( ' Please enter your password: ' ) IF name == ' Stephan ' and pwd == ' 123 ' : Print ( " Welcome to ... " ) the else : Print ( " user name or password is incorrect " )
Cast
int = S (INPUT ( " enter a user name " ))
11. Three flow control statements
1. execution order
2. branch selection (the else-IF)
IF expression:
executing code
elif expression:
executing code
...
the else:
executing code
Description: only need to meet a condition, program which condition the following code execution, and then exit
3. loop
for loop, break, continue
# Print to 0. 9 for I in Range (10 ): Print (I) # another method Li = [. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9, 10 ] for I in Li: Print (i) # next continue a cycle, the police check ID, do not know the search for i in li: IF i <5 : continue # do not go forward, directly into the next cycle Print (i) # print 5678910 # direct break out of the entire loop, police catch the bad guy for i in li: IF i> 5 : BREAK Print (i) # print 12345
while loop
while the expression:
code execution
the while True: Print ( " hahah " ) COUT + =. 1 IF COUT> 100 : Print ( ' out of the loop ... ' ) BREAK
Iterator:
for i in xxxx: print(i)