Python practice questions

Python practice questions

1. Briefly describe the difference between compiled and interpreted languages, and list which languages ​​you know are compiled and which are interpreted?
Answer:
Concept:
Compiled language: Compile all prepared source programs into binary code executable program. Then, you can run the program directly.
Interpreted language: translate one sentence of the completed source program, and then execute one sentence until the end!

Difference:
Compiled language: fast execution, high efficiency; dependent on the compiler, poor cross-platform. Such as C, C++, Delphi, Pascal.
Interpreted language: slow execution, low efficiency, dependent on interpreter, good cross-platform. Such as Python, Java, PHP, Ruby.

2. What are the two ways to execute a Python script?
Answer:
Enter the interactive mode of the interpreter: easy to debug, can't save the code
script file permanently: save the code permanently, but inconvenient to debug

3. What are the Python single-line comments and multi-line comments?
Answer:
single-line comments "#" (Multi-line comment in PyCharm: select the code to be commented, Ctrl+?)
Or use a pair of triple single quotes ''' ''' and a pair of triple double quotes """ """

4. What are the boolean values?
A:
One True, one False

5. What are the precautions for declaring variables?
Answer:
1) The variable name can only be any combination of letters, numbers or underscores
2) The first character of the variable name cannot be a number
3) The keyword cannot be declared as a variable name ['and', 'as',
'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from',
'global', 'if', 'import', 'in ', 'is', 'lambda', 'not', 'or', 'pass', 'print',
'raise', 'return', 'try', 'while', 'with', 'yield']

6. How to check the address of a variable in memory?
Answer:
id (variable name)

Guess you like

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