Simple little exercise

Today a practice:

1, the type and characteristics of the python interpreter

CPython:
The most widely used development language interpreter c
IPython:
Based on an interactive timer on the cpython, interactively enhanced functionality and cpython as
PyPy:
The goal is efficiency, improve the efficiency
JPython:
running Java on again the interpreter, directly to the python code is compiled into Java byte code execution
IronPython:
run the interpreter on the Microsoft .NET platform, the python compiled to .NET bytecode execution

//////////////////////////////////////////////////////////////////////////////////////////

2, citing at least five PEP8 specification (the more the better, to search their own)

International practice, file encoding, and encoding format python. 8-all UTF
Pytho code string non-ASCII characters, the need to add a prefix u
package name, module name, local variable names, function formula underlined lowercase + hump
global variables: ALL cAPS underlined hump
class name: capitalized hump type
variable named after: try to reflect the type of data structure variable and specific meaning
variable names, class names, the name must be meaningful. Forbidden to use single-letter
variable names do not use the keyword system, such as dir type str, etc.
Note: You must use methods marked notes, if it is a public api method or related methods provide both, it is best to use the given sample
module Note: In the beginning to add a comment to the module
general comment stage it should start with "#" and a single space start
method returns, regardless if the data structure complicated, it must be done explanation of each property returns the results of
the front page: references in the page css and js, or configuration path, you must use the "absolute path" instead of '../','./' and other reference relative path

3, brief language and compiled interpreted language

Interpreted: using an interpreter to execute the interpreter for the program is a sentence translated into machine language to perform such python

compiled: using a compiler to be compiled into machine language, and can be run directly, such as c language

//////////////////////////////////////////////////////////////////////////////////////////

4, bit, B, KB, MB, GB relationship

8bit = 1B
1024B =1KB
1024KB =1MB
1024MB =1GB

///////////////////////////////////////////////////////////////////////////////////////////

5、列举你所了解到python2和python3的区别

一.用户交互中
python2中:input一定要声明你输入的类型
python3中:无论用户输入的是什么类型,最终返回的一定是字符串。相当于python2中的raw_input

二.整型中
python3:都是int类型
python2:范围[-24xxxxxxxx-24xxxxxxxx]
超过这个范围是long,其他是int

三.字符串类型中
python2中: str本质是一个拥有8个bit位的序列
python3中: str本质是一个unicode序列

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


6、is和==的区别

is用来计较两个变量的地址值id是否相同

==用来比较两个变量值value是否相等

返回值都是布尔类型

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

7、一行代码实现数值交换

a,b =b,a

//////////////////////////////////////////////////////////////////

8、列举常用的字符串格式化的方式

1).%s:可以接收任意类型的变量
%d:只能接收数字类型的变量
name=input(" ")
age=input("")
age=int(age)
eg:print("my name is %s,my age is %d"%(name,age)) 按照传输顺序传值

2).format
print("my name is {name},my age is {age}".format(name=name,age=age))
print("my name is { },my age is { }".format(name,age)) 按照传输顺序传值

3).f-string
print(f"my name is {name} , my age is {age} .")

9、python垃圾回收机制

python垃圾回收机制是python解释器中的自带的一种机制,用于回收不可用的变量的值所占用的内存空间

a.引用计数
当变量的值的引用计数为0时,垃圾回收机制会自动清除

b.标记-清除
当应用程序将内存撑满后,程序自动停止,垃圾回收机制自动清除

c.分代回收
根据存活时间来将变量划分不同等级,等级越高,被扫描的频率越低

///////////////////////////////////////////////////////////////////////////////////////////////////

10:求结果(自己先想,想完在执行):

```python
v1 = 1 or 3
v2 = 1 and 3
v3 = 0 and 2 and 1
v4 = 0 and 2 or 1
v5 = 0 and 2 or 1 or 4
v6 = 0 or Flase and 1
```
v1 =1
v2 =3
v3 =0
v4 =1
v5 =1
v6=False

 

Guess you like

Origin www.cnblogs.com/godlover/p/11790121.html