Enter the python world. Understand the implementation of python interaction and common development tools

After installing python environment and the required packages, they begin a journey python programming.

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

One, Interactive

Interactive environment enter the command enter, it will execute the command. The advantages of convenient operation, write directly to direct translation, shortcomings, can not save, close the window disappears.

1564389471755

Second, the imperative

Open the text file, enter the command, save. Then open cmd terminal, locate the file directory, and run it with python. Text editor to write the code meaningless, just a bunch of characters, and does not affect the file extension. The advantages of permanent preservation. The disadvantage of all written to run.

Why use 2.IDE and IDE (Integrated Development Environment)

Interactive and can not be saved imperative not immediately compile and run, so at this time to play a IDE development tools, a lot of language has its own popular development tools such as java in Eclipse. The python's two development tools for the best the two: pycharm and jupyter.

pycharm is an application that actually improved the shortage imperative. It can be permanently stored and can immediately compile and run.

Nature jupyter Notebook is WEb application, easy to create and share documents, compile and run online and can be stored permanently.

2. Description of python garbage collection

When we define a variable, the computer will open up this memory to store variables. When this variable points to the next value, the original value of the call is not variable, the count variable is called point to the reference count value. When the value of a reference count of zero, it becomes garbage python eyes. python will dispose of this garbage, freed memory occupied. This is the python garbage collection mechanism.

3. For the following code

x = 10
y = 10
z = 10
 de1 y

10 reference count of how many?

2

x = 257
y = x
del x
z = 257

Variable x corresponds to the value of the reference count 257 is the number?

1

4, a small integer pool concept is outlined python:

Python For efficiency, to avoid efficiency because the same value is repeated to create memory space brought about by the application, Python interpreter created when the starting pool small integer range [-6,256]. Small Integer object within the range is to be reused in the global interpreter, it will never be recovered out of the garbage collection mechanism.

It is worth mentioning that, in pycharm, for the consideration of the performance, expanding the scope of small integers pool, such as short period of time defined variables or the original variable id.

5, for X = 10, please use python code print variable values, respectively, the memory address of the variable value and the variable data type.

x = 10
print(x)
print(id(x))
print(type(x))x=


10

140717743956912

int

For the following codes:

x = 257
y = x
z = 257

Please determine x \ y \ z values ​​are the same? x \ y \ z where the same memory address? Please elaborate why the python code?

print(id(x))

2487910418320

y = x

print(id(y))

2487910418320

print z = 257 (d (z))

2487910840432

6. preview written by guessing the age of a game, demand: given a standard of age, the age of the user through the input is equal standards to determine the age of the age, if equal, congratulations, guessed, if less than, guess smaller, if more than, Print guess big.

age = 20
count = 0
while count < 4:  
    inp_age =int (input ("输入你的年龄"))   
    if inp_age == age:      
        print("你真厉害")       
        break   
    elif inp_age < age:     
        print("猜小了")  
    else:
        print("猜大了哦")  
        count=count+1

Guess you like

Origin www.cnblogs.com/wwbplus/p/11266833.html