Python record--data type (only after viewing the data, my own understanding, if there is something wrong, please let me know, there may be some other people's things and links, if not allowed, please let me know)

Seven standard data types:

 • Numbers

• String

• List

• Tuple (tuple)

• Dictionary

• set (collection)

• Bool

Numbers

feature:

  1. Numbers are immutable data types, which means that changing the number data type allocates a new object.

   2. When the variable value is changed, it will automatically reallocate a memory space address, and automatically release the memory address before the change.

Four different number types:

       int (signed integer): commonly referred to as an int or integer, is a positive or negative integer without a decimal point.

      long (long [can also represent octal and hexadecimal]): an integer of infinite size with an upper or lower case L at the end of the integer.

      float (floating point type): A floating point type consists of an integer part and a fractional part, and a floating point type can also be represented in scientific notation (2.5e2 = 2.5 x 102 = 250)

      complex (complex number): A complex number consists of a real part and an imaginary part, which can be represented by a + bj, or complex(a,b). The real part a and the imaginary part b of the complex number are both floating-point types.

String

1. A string is any text enclosed in single quotes ' or double quotes "

2. Strings have two data types: str type and unicode type. The ASCII encoding used by the str type means that it cannot represent Chinese. The unicode type adopts unicode encoding and can represent any character, including Chinese and other languages

3. The default encoding of Python2 is ASCII, which cannot recognize Chinese characters, so the character encoding needs to be explicitly specified; the default encoding of Python3 is Unicode, which can recognize Chinese characters.

4. ASCII encoding is suitable for English characters, Unicode is suitable for non-English characters (such as Chinese, Korean, etc.), and utf-8 is a format for storage and transmission, which is a re-encoding of Unicode characters. So we need to indicate when coding: #-*- coding: utf-8 -*-

list

1. A list is a modifiable collection type. Its elements can be basic types such as numbers and strings, or collection objects such as lists, tuples, and dictionaries, or even custom types.

2. It is an ordered collection where each element is assigned a number - its position, or index, the first index is 0, the second index is 1, and so on

material:

 Sharding, public methods supported by lists, converting lists to iterators: https://www.cnblogs.com/fengzheng/p/3590891.html

Update, delete, list functions\methods:

    http://www.runoob.com/python/python-lists.html

Tuple

1. Tuple creation is very simple, just add elements in parentheses and separate them with commas

2. When the tuple has only one value, you need to add (,) comma. Columns such as: t=(1,)

Dictionary

1. The dictionary is unordered and accessed by key

2. Use key-value (key-value) storage, with extremely fast search speed

3. The key must be unique,

material:

https://www.cnblogs.com/scios/p/8108243.html

https://blog.csdn.net/qq_15654993/article/details/75267569

set

1.Set is an unordered set of non-repeating elements. Unlike lists and tuples, sets are unordered and cannot be indexed by numbers

2. Basic functions include relationship testing (operation) and eliminating duplicate elements. Collection objects also support union, intersection, difference, symmetric difference, etc.

3. Note that you can only use s=set() when creating an empty set, because s={} creates an empty dictionary

4. When creating a collection that is not empty, use {}

material:

Collection type operations: https://blog.csdn.net/business122/article/details/7541486

https://blog.csdn.net/u013291394/article/details/50371760

https://www.cnblogs.com/whatisfantasy/p/5956775.html

 

Bool

1. Application: make logical judgments

2. The boolean type has only two values: True and False

 

material:

http://www.iplaypy.com/python-100/20541.html

https://www.cnblogs.com/fengzheng/p/3590891.html

https://www.cnblogs.com/chenwolong/p/6496672.html

https://www.cnblogs.com/snaildev/archive/2017/09/18/7544558.html

 

Terminology:

  Mutable and immutable types

       Mutable types: lists, dictionaries, sets

         Specific explanation: If it is a variable type, when operating on an object, you do not need to apply for memory elsewhere, you only need to apply for (+/-) consecutively after the object, that is, its address will remain unchanged. But the region will be longer or shorter. Insert data in memory, that is, the memory address does not change, and the value changes.

      Immutable types: numbers, strings, tuples

         Specific explanation: When operating on the object itself, you must apply for a new area in memory (because the old area #immutable#). Immutable means that the value in the memory space of the address does not change, and if the value changes, the address memory space is re-applied. The old memory space, when unused, is automatically garbage collected . When the memory address moves, the value also moves

         Summary: Immutable data types do not allow the value of the variable to change. If the value of the variable is changed, it is equivalent to creating a new object. For objects with the same value, there is only one object in memory, and there will be a reference inside. count to keep track of how many variables refer to this object;

The variable data type allows the value of the variable to change, that is, if the variable is append, +=, etc., it will only change the value of the variable, but will not create a new object, and the address of the object referenced by the variable will not be Change, but for different objects of the same value, there will be different objects in memory, that is, each object has its own address, which is equivalent to saving multiple copies of objects of the same value in memory, and there is no reference count here. , is a real object

  Reference: Variable and immutable https://blog.csdn.net/dan15188387481/article/details/49864613

 

  Reference count:

       When a reference is passed as a parameter to getrefcount(), the parameter actually creates a temporary reference. Therefore, the result obtained by getrefcount() will be 1 more than expected

   Reference materials: reference counting, objects, garbage collection, reference ring, generational recycling https://www.cnblogs.com/vamei/p/3232088.html

  Memory allocation: none, no information found, also very confused

 

 

doubt:

   1. Immutable type question:

           Code:          

Question 1: When a memory value is created, when referenced again, the memory address is the same

                             Question 1: Why are the memory addresses different? I saw an answer that the memory address changes when the value is too large,

                             Question 2: If the above question says, then what is the value too large? (after 100, after 200,,,,)

Question 2: When a value is created, a memory space is allocated.

                               Question 1: What about the rules for allocating memory space? I see that some variables have large memory space and some variables have small memory space?

 

 

             

Guess you like

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