This commit is contained in:
guanjihuan 2025-03-01 23:57:16 +08:00
parent 5f3d81fc6c
commit 9cad8f4a9d
2 changed files with 61 additions and 2 deletions

View File

@ -3,9 +3,9 @@ import pickle
data = [1, 2, 3] data = [1, 2, 3]
# 保存为文件 # 保存为文件
with open('a.txt', 'wb') as f: with open('a.pkl', 'wb') as f:
pickle.dump(data, f) pickle.dump(data, f)
with open('a.txt', 'rb') as f: with open('a.pkl', 'rb') as f:
data_load_from_file = pickle.load(f) data_load_from_file = pickle.load(f)
print(data_load_from_file) print(data_load_from_file)
print() print()

View File

@ -0,0 +1,59 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/45201
"""
# False 布尔值
print(bool(False))
print(bool(0))
print(bool(0.0))
print(bool(0.0j))
print(bool(None))
print(bool(''))
print(bool([]))
print(bool({}))
print(bool(()))
print(bool(set()))
print()
# 虽然布尔值相同,但只有 False, 0, 0.0, 0.0j 和 False 等价
print(False==False) # True
print(False==0) # True
print(False==0.0) # True
print(False==0.0j) # True
print(False==None) # False
print(False=='') # False
print(False==[]) # False
print(False=={}) # False
print(False==()) # False
print(False==set()) # False
print()
def true_or_false(a):
if a:
print('True')
else:
print('False')
# 'if' 环境中的 False 测试
true_or_false(False)
true_or_false(0)
true_or_false(0.0)
true_or_false(0.0j)
true_or_false(None)
true_or_false('')
true_or_false([])
true_or_false({})
true_or_false(())
true_or_false(set())
print()
# 'if' 环境中的 True 测试
true_or_false(True)
true_or_false('True')
true_or_false('False')
true_or_false('a')
true_or_false(1)
true_or_false(-1)
true_or_false(2)
print()