Summary of basic knowledge of python

First, the advantages and disadvantages of python

  advantage:

  1. Beautiful, clear, simple
  2. high level language
  3. High development efficiency
  4. Portability, Extensibility, Embeddability

  shortcoming:

  1. running slow
  2. Code cannot be encrypted
  3. Threads cannot take advantage of multiple CPUs

Second, the difference between python2 and python3

  Code:

  1. python2: code confusion, more repetitive code, redundant
  2. python3: code advocating beauty, clarity and simplicity

  print:

  1. python2: print is a statement
  2. python3: print is a function

  input:

  1. python2: raw_input() receives strings, input() receives numbers
  2. python3: input() receives all strings

  Encoding:

  1. python2: The default encoding is ASCII code (if you want to use Chinese: #_*_coding:utf-8_*_)
  2. python3: The default encoding is utf-8, which supports Chinese

  Inequality operator:

  1. python2: you can use != or ><
  2. python3: only use !=

  Create an iteration counter:

  1. python2:xrange
  2. python3:range

  repr:

  1. python2: repr can be a statement
  2. python3: only repr() function is allowed

  document:

  1. python2: you can use != or ><
  2. python3: only use !=

  Integer:

  1. python2: there is a long type
  2. python3: all are int

  Modify the syntax:

  1. python2: dictionary keys, values, items and map, filter, reduce return a list
  2. python3: dictionary keys, values, items and map, filter, reduce return an iterable object

  Added syntax:

  1. python2: print and exec statements, no methods like nolocal
  2. python3: print and exec are changed to functions, new methods such as nolocal are added

  inherit:

  1. python2: default classic class (required for new-style classes (object))
  2. python3: only new-style classes

3. Types of Development

  compiled

  Disadvantages: slow troubleshooting, low development efficiency, not portable

  Advantages: high execution efficiency

  Typical: C language, go language

  interpretive

  Disadvantage: low execution efficiency

  Advantages: fast troubleshooting, high development efficiency, portability

  Typical: python, PHP

  Hybrid

  Typical: java, C#

4. Types of python

  Cpython: based on C language development

  lpython

  Jpython

  PyPy: currently the fastest performing

5. Variables and constants

  Constant: a constant that remains unchanged, commonly known by convention, all capitalized as constants

 

  Variables: Store the running results of the program in memory for later code calls

  Require:

  1. Must consist of numbers, letters, and underscores
  2. cannot start with a number
  3. cannot be a keyword
  4. Can't be Chinese, can't be too long, must be descriptive
  5. The official website recommends underscore old_boy and hump OldBoy

6. Statement

  if statement

   elif branch judgment

  while statement

   flag (flag bit)

   break (completely ends the loop)

   continue (jump out of this loop)

   else (the loop exits execution normally)

  for statement 

   break (completely ends the loop)

   continue (jump out of this loop)

   else (the loop exits execution normally)

  in,not in

s = ' old boy alexwusir ' 
print ( ' old boy '  in s)     # True 
print ( ' old boy wusir '  in s)     # False 
print ( ' old boy '  in s)     # True 
print ( ' old boy '  not  in s )     # False

#The result shows that in a string, the defined substring contained in a parent string must be True if it is continuous, False if it is not continuous, in means inclusion, not in means non-inclusion

7. Logical operators

# and or not #The 
first type: before and after are all comparison operations. 
#Priority : () > not > and > or the same priority, calculated from left to right. 
print (1 > 2 and 3 < 4 and 3 > 2 or 2 < 3 ) # True
 print (2 > 1 and 3 < 4 or 4 > 5 and 2 < 1 ) # True
 print (1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8 ) # False #The
 second type: both front and back are numerical operations. 
'''
x or y if x True,则 return x,否则 return y
'''
print(1 or 3)  # 1print(2 or 3)  # 2
print(0 or 3)  # 3
print(-1 or 3)  # -1
print(1 and 2)  # 2
print(0 and 2)  # 0

#The third type: mix. 
print (1 > 2 or 3 and 4 ) # 4
 print (2 or 2 > 3 and 4 ) # 2
 print (0 or 2 > 3 and 4 ) # False

#Data type conversion: 
'''
int ---> bool non-0 is True, 0 is False
bool---> int  True  1  False 0
print(int(True))
print(int(False))
print(bool(100))
print(bool(0))
'''

Eight, formatted output

# % placeholder s str string d digit number 
# The first type: 
name = input( ' Please enter your name: ' )
age = input( ' Please enter your age: ' )
hobby = input( ' Please enter your hobby: ' )
msg = ' My name is %s, I am %d this year, and my hobby is %s ' % (name,int(age),hobby)
 print (msg)
 #The second 
dic = { ' name ' : ' old boy ' , ' age ' :51, ' hobby ' : ' It doesn't matter ' }
msg = ' My name is %(name)s, this year is %(age)d, and my hobby is %(hobby)s ' % dic
 print (msg)

# Simply displaying % in formatted output is resolved with %%. 
name = input( ' Please enter your name: ' )
age = input( ' Please enter your age: ' )
msg = ' My name is %s, I am %d, and my learning progress is 1%% ' % (name,int(age))
 print (msg)

9. Coding

  1. Telegram: Didi Didi is actually a high and low level.
   Codebook :
   today 0000 0001
   days 0000 0101
   drink 0000 0011
   wine 0000 1100
   go to 0001 1010
   ya 0001 0001

   0010010 1000011 1100101 010001

  2, when the computer stores and transmits, 01010101
        initial codebook:
    asiic contains numbers. Eight bits
    01000001 01000010 01000011 ABC
    8 bits = 1 byte represents a character.

    Universal code unicode, the language of all countries is included in this codebook.
    Initial: 16 bits, two bytes, representing one character.
    A: 00010000 00010010
    Medium: 00010010 00010010
    Upgrade: 32 bits, four bytes, representing one character.
    A: 00010000 00010010 00010000 00010010
    Medium: 00010010 00010010 00010010 00010010
    Resource waste.

    Upgrade: utf-8. At least 8 bits (one byte) are used to represent one character.
    English: a :00010000 represents a character with 8 bits.
    Europe: 00010000 00010000 16-bit two bytes represent a character.
    In Asia: 00010000 00010000 00010000 24 bits, three bytes represent one character.

    utf-16

    gbk: GB.
    Contains only: English and Chinese.
    English: a: 00010000 8 bits, one byte represents one character.
    Chinese: Medium: 00010000 00010000 16 bits, two bytes represent one character.
    gb2312.....

    8 bits = 1byte
    1024byte=1kb
    1024kb = 1MB
    1024MB = 1GB
    1024GB = 1TB

  Python basic mind map link: https://www.processon.com/view/link/5ae71b80e4b019d3a919be99

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325116032&siteId=291194637