Knowledge -python data type 1

table of Contents

  1. Description of garbage collection
  2. Reference counting exercise
  3. Description of small integers pool concept
  4. For x = 10, respectively, please use python code print variable values, variable values ​​and the variable data memory type
  5. For the following codes:
x = 257
y = x
z = 257

Please judge x, y, z values ​​of the variables are the same? x, y, z where the memory address is the same? Please elaborate why the python code?

  1. Digital Type Description
  2. Description string type

text

  1. Brief Python garbage collection:
    • Reference count: references to the objects the counter is 0, automatically reclaims the memory
    • Clear labeling: fast trigger memory overflow, clear a specific variable names. Resolve the circular reference problem
    • Generational Recovery: Depending on the median survival time is divided into different levels, the lower, the higher the level garbage collection sweep frequency
  2. For the following codes:
x = 10
y = 10
z = 10
del y

10 reference count of how many?

Reference count 2

x = 257
y = x
del x
z = 257

Corresponding to the variable x 257 reference count of how many?

Reference count 2

  1. Brief Python small integer pool concept:

    Python implementation int time there is a small integer pool. In order to avoid creating the same value repeated application memory space efficiency brought about by the range [-5,256], small integer objects within that range is to be reused within the scope of the global interpreter, will never be garbage collection recycling.

  2. For x = 10, with Python code print variable values, respectively, the memory address of the variable value and the variable data types:

x = 10
print(x)
print(id(x))
print(type(x))
  1. For the following codes:
x = 257
y = x
z = 257

Please judge x, y, z values ​​of the variables are the same? x, y, z where the memory address is the same? Please elaborate why the python code?

The same value

Pycharm the same memory address, different in cmd

a1 = print(x)
b1 = print(y)
c1 = print(z)
a1 = b1 = c1

a2 = print(id(x))
b2 = print(id(y))
c2 = print(id(z))
a2 =! b2
a2 =! c2
b2 =! c2
  1. Digital Type Description

    • Integer

      Role: that age, number, etc.

      Defined way

      x = 1
      x = int(1)
    • Float

      Role: represents the height, weight, etc.

      Defined way

      x = 1.0
      x = flout(1)
  2. Description string type

    Role: table name, gender, appearance, etc.

    Defined method:

    String is a string of the character string to string together, in a single or double wrapped string of characters triple quotes

name = 'bigb'
sex = "male"
hobby = '''
sing
dance
rap
basketball
'''

Guess you like

Origin www.cnblogs.com/binyuanxiang/p/11494526.html