Python Study Notes sixth day

Python Study Notes sixth day

1. Review and expand learning content

   Dictionary 1.1

          Using the hash key data type as

          Dictionary CRUD operations, details see notes yesterday

          Nested, unpacking, etc.

2. Learn Today

   2.1 is the difference between "==" in

          2.1.1 Variable: to identify (ID) area of ​​memory, memory substantial sake of convenience, the manipulated variable is: directed manipulated variable that memory unit. The compiler is responsible for informing the computer to allocate memory. Can use built-in functions Python id () to get the variable address, id (object) Returns the object located in the object memory address in its life cycle

          2.1.2 Memory: Memory is used to store data in computer hardware, can be understood as: the memory is a grid composed of a small size of each grid is a byte can store data of 1byte. You need to rely on memory to find the address data. Memory address is an identifier, the equivalent of house numbers.

Find the memory address - "Operation Memory -" as follows: operating variables

         2.1.3 difference

Everything in python objects, between objects can use the "==" and is, difference is:

           id is a comparison of the two objects are equal, that is, compare two objects for the same actual object, point to the same piece of memory.

          "==" is content to compare two objects are equal, the default calling object de __eq __ () method

           Internal Python is optimized to work for integer objects, some Python integer frequently used objects cached, saved to small_list list. In Python's entire life cycle, from anywhere to call these small integers, you do not need to re-create an object. Range [-5 to 256]

note:

1. Small Integer object is reused globally interpreter will never be recovered. Immutable objects with a block of code, as long as the values are equal, does not create a new object.

2. For reasons of performance, all immutable objects in the same code module, the same value as long as the object created will not be repeated.

(* Less than 20 in a single string, the memory address is the same. If so, that is * 21 or more, or a different memory address. Cut can not exist special characters that must consist of all letters) (Python3.7 and later Not applicable)

3. Not only is plastic, string also comply with these rules

Review: The variable type immutable type

Variable data types

tuple string string integer tuple of type int boolean bool

Variable data type:

Dictionary dict collection set in list

2.1.4 code block: the minimum basic unit of program

Python program code block is based on the composition.

A block of code file, a function body, a class, interactive command line are regarded as a single line in the code block.

Py file in a similar situation, but not the same place.

1.int type, as long as the same value in the same block, the same address

2.str type, as long as a length of not more than 20, even if the special characters, the same addresses

 

3. The encoding and decoding

3.1 Common Encoding: binary 01

3.2 encoding and decoding (in ASCII for example)

3.2.1 Introduction

Encoding and decoding a mapping relationship.

Decoding, such as the ASCII character A corresponding to decimal 65, the corresponding binary code is 01,000,001.

Reverse engineering is the encoded decoding, when the computer would read 01000001 view corresponding to ASCII table corresponding to A

Decoding encode: Really correspondence between the character and binary string, that is

Real Character -> binary string

Encoding decode: correspondence between the binary string with real character, that is

Binary string -> true character

Note: 1 should be encoded and decoded to a same code

2. In the beginning of the file, specify the encoding, for example,

#-*-coding:utf-8-*- (python)

<meta charset = 'utf-8'>(html)

@ Charset'utf-8 '(CSS style)

3.2.2 common coding

3.2.2.1 ASCII

It does not support Chinese, support alphanumeric symbols

8 byte

3.2.2.2 GBK GB code

Support in English, numbers and symbols

English 16 2-byte

Chinese 2-byte 16-bit

3.2.2.3.Unicode Unicode

Support in English, numbers and symbols

English 32 4 bytes

Chinese 4-byte 32-bit

3.2.2.4.UTF-8 nations variable length code

Support for all

English 8 1 byte

Chinese 24 1 byte

Note: Python 2 default ASCII encoding, Python 3 default display all content pycharm Unicode UTF-8 default

 

Guess you like

Origin www.cnblogs.com/tjlhappyboy/p/11209692.html