Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Python develops common knowledge points, how many do you know?


May 30, 2021 Article blog


Table of contents


This paper mainly explains the basic grammar knowledge point commonly used in Python development, which is a high-frequency basic knowledge point, mainly familiar knowledge point.

First, encoding formatting

  1. --coding: utf-8 --- the specified encoding format is UTF-8
  2. --coding: GB2312 -

Second, common escape characters

  1. Line breaks
  2. Tabs
  3. Enter
  4. The character of ""
  5. 'Single quote'
  6. "Double Quotes"

Third, operators (unconventional)

  1. The multiplication operator
  2. Take the whole operator
  3. and
  4. or
  5. Not non
  6. In contains, the same sex operator, to determine the unique identifier between objects, that is, the id is the same (the same string hash value may be the same but the id is different)
  7. not in does not contain
  8. The is identity operator that determines whether two descriptors are referenced from the same object
  9. is not identity operator to determine whether even a descriptor is applied from a different object

Four, commonly used constants

  1. import import module
  2. from ... i mport imports the module branch
  3. Used within the global function (method), the promotion variable is a global variable
  4. None has no value for the object, none
  5. True true
  6. False false
  7. "" Empty string
  8. () Empty tuple
  9. An empty list
  10. An empty dictionary

V. Operator priority

  1. Index (highest priority)
  2. - Flip by bit, dollar plus sign and minus sign (the last two methods are named . . . . . . .
  3. : % / / Multiply, divide, mold and dissolication
  4. - Addition subtraction
  5. >> << move right, move left operator
  6. Bit 'AND'
  7. ^ | B it operator
  8. < is < > >. . .
  9. <> is equal to the operator
  10. % s /-//-----
  11. Is is not identity operator
  12. In not in member operator
  13. not or and logical operator

Six, data classification

  1. Standard data types Numbers, Strings, Lists, Tuple (Tuple), Sets (Collections), Dictionary (Dictionary)
  2. Immutable Data Numbers, Strings, Tuples
  3. Variable Data List, Set, Dictionary (Dictionary)
  4. Numbers int, float, bool, complex (plural)

Seven, iterators and generators

  • The iterator iterator is an object that remembers the location of the traversal. A way to access collection elements

Basic methods: iter() and next()

  • The generator uses a function called the generator, which is a function that returns the iterator and can only be used for iterative operations.

During the call generator run, each time the return is encountered, the function pauses and saves all current run information, returns the value of the yield, and continues to run from its current position the next time the next method is executed

Eight, anonymous function

  1. Python uses lambda to create anonymous functions.
  2. Lambda is just an expression and cannot access parameters outside its own argument list or in a global namespace

Grammar: lambda (arg1), arg2 , arg3...) : expression;

Nine, collection

  • A set of out-of-order, non-repetitive elements, represented by the use of set() instead of , which defaults to an empty dictionary

Ten, scope

  1. Internal functions that do not modify global variables to access global variables
  2. An internal function that modifies a global variable with the same name, python considers it a local variable
  3. Calling a variable name(such as print sum) before an inrone modifies a global variable with the same name raises Unbound-LocalError

Eleven, module

  1. Store these definitions in a file for use by scripts or interactive interpreter instances, which are called modules.
  2. A module is a file that contains all the functions and variables you define, and the suffix name is .py. M odules can be introduced by other programs,
  3. to use functions such as functions in the module. T his is also how to use the python standard library.