Python面试题(整理)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41402059/article/details/81914376

什么是编译型、解释型?有什么区别?

编译型:一次性将全部代码编译成二进制文件。如C、C++等语言。

优点:运行效率高

缺点:开发速度慢、不能跨平台

解释型:程序运行时从上至下一行一行的解释成二进制。

优点:开发速度快、效率高、可以跨平台

缺点:运行效率低

Python2和Python3的区别?

Python2源码重复率高、不规范,且Python崇尚简洁优美,因此进化为Python3,规范化

Python基础数据类型?

to do

逻辑运算:

优先级:() > not  > and > or

# 优先级 () > not > and > or
print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
# 相当于print((2 > 1 and 1 < 4) or (2 < 3 and 9 > 6) or (2 < 4 and 3 < 2))
# 即 print( True or True or False),因此结果为True
 
print(3>4 or 4<3 and 1==1) # F
print(1 < 2 and 3 < 4 or 1>2 ) # T
print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F

当运算符两边为数字时,如 x or y ,x非0则返回x,否则返回y。当x and y 时与or相反 x为0返回x,否则返回y

print(0 and 2) # 0
print(1 and 2) # 2
print(0 or 1) # 1
print(1 or 2) # 1
 
print(1 > 2 and 3 or 4 and 3 < 2) # False
print(1 or 1 < 3 and 2) # 1

程序运行结果?

a, b = [1, 2]

结果:a = 1  b = 2

猜你喜欢

转载自blog.csdn.net/weixin_41402059/article/details/81914376
今日推荐