1、int()强制转换浮点数
在int()的强制转换浮点数时候,不管是正数还是负数,只取整数部分。
print(int(6.235)) # 6 print(int(-6.235)) # -6
注意:这里不是向上或者向下取整,也不是四舍五入。
2、注意操作的返回值
a = print("python") print(a) # None
list_1 = [1,2,3] list_2 = [4,5,6] print(list_1.extend(list_2)) # None print(list_1) # [1, 2, 3, 4, 5, 6]
list_3 = [1,6,5,8,7,9,4,1,3] new_list = list_3.sort() print(new_list) # None print(list_3) # [1, 1, 3, 4, 5, 6, 7, 8, 9] list_4 = [1, 6, 5, 8, 7, 9, 4, 1, 3] new_list = sorted(list_4) print(new_list) # # [1, 1, 3, 4, 5, 6, 7, 8, 9] print(list_4) # 不变[1, 6, 5, 8, 7, 9, 4, 1, 3]
3、字典中按照键的顺序输出
dict_1 = {"c": 45254, "a": 333, "b": 908} for key in dict_1: print(key, dict_1[key]) for key in sorted(dict_1): print(key, dict_1[key])
c 45254 a 333 b 908 a 333 b 908 c 45254