python variables, variable properties

1. Briefly execute Python program in two ways, and their advantages and disadvantages

A : Interactive advantages: can immediately see the results, easy troubleshooting. Interactive drawback: the code can not be saved, power disappears

Command type advantages: code is stored permanently. Command type Disadvantages: easy troubleshooting

2. Description of Python garbage collection:

A : When you delete a variable name or the names of variables redefined, pythom garbage collection mechanism will automatically clears variable values

3. For the following codes:

x = 10
y = 10
z = 10
del y

10 reference count of how many?

Answer : 2

x = 257
y = x
del x
z = 257

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

Answer : 2

4. DESCRIPTION pool concept is a small integer Python

A : In order to reduce the value of re-use duplicate memory, python established a pool of small integers from [-5,256] from the start python program began, it has been in memory, will not be garbage collection mechanism

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

A : print (x) 10

print(id(x)) 1671390528

print(type(x)) <class 'int'>

6. For the following codes:

x = 25
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 on why the use python code

A : print (f "x memory id: {id (x)} ")

print (f "y memory id: {id (y)}")

print (f "z Memory id: {id (z)}")

x Memory ID: 1671390768
Y Memory ID: 1671390768
Z memory id: 8772896

7. guess the age

age = 18
count = 0
hengxian = ("=" * 10)
while count < 3:
    print(f"{hengxian}让我们开始猜年龄的游戏吧!{hengxian}")    
    get_age = input("请输入您的年龄:")    
    # 判断是否输入数字    
    if not get_age.isdigit():
        print("请输入数字!")
    break
   
        get_age_int = int(get_age)
        if get_age_int == age:
            print("你猜中了!!!!!!!!!!!!!!!!!!!!!1")
        elif get_age_int > age:
            print("你猜的数字大了")
        elif get_age_int < age: 
            print("你猜的小了")

https://www.cnblogs.com/kuck/

Guess you like

Origin www.cnblogs.com/kuck/p/11266658.html