给自己记个笔记,随学随更新~ 撒花~
-
python 2x 与 python 3x的区别 *****
08年龟叔更新了python两个版本
python2.x:源码不规范,源码重复较多
python3.x:源码清晰,优美,简单。python3x:打印的中英文,全部都能显示。
因为默认编码方式:utf-8(包含中文,英文,欧洲文字)
python2x:对于中文,报错。
默认编码方式:ASCII(包含英文)
解决方式:首行输入代码
# -*- encoding:utf-8 -*-
简写: encoding
(改变python2的编码方式) -
逻辑运算符相关
print(1 or 3 and 5 or 4)
print(0 or 3 and 5 or 4)
注:优先级为() > not > and > or
x or y if x is True, return x
and与or相反
答案是:1 5
变态面试题:
print(1 > 2 or 3 and 4 < 6)
print(2 or 3 and 4 < 6)
print(0 or 3 and 4 < 6)
print(1 or 3 and 4 < 6)
print(3 and 4 < 6 or 0)
print(0 or 3 and 4 > 6)
print(3 and 4 < 6 and 0)
答案是:True 2 True 1 True False 0