python3 Return as when dividing float type ,python2 The return is int type
# python3
[email protected]-virtual-machine:/home# python3
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(4 / 2)
2.0
# python2
[[email protected] local]# python
Python 2.7.5 (default, Nov 16 2020, 22:23:17)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print(4 / 2)
2
>>>
python3 in dict.items() The return value is dict_items type , python2 in dict.items() The return value is list
dicts = {
"name": "lisi", "age": 1}
dicts2 = {
"class": " mathematics ", "score": 100, "name": "maliu"}
# Python3 Of dict.items() The return value is changed from the original list to dict_items type
print(type(dicts.items())) # <class 'dict_items'>
print(dict(dicts.items())) # {'name': 'lisi', 'age': 1}
print(list(dicts.items())) # [('name', 'lisi'), ('age', 1)]
stay python3 in map Function returns map Object of type , And in the python2 in map Back to the list .
# python3
def square(x):
return x ** 2
res = map(square, [1, 2, 3, 4])
print(list(res))
print(type(res))
// output
[1, 4, 9, 16]
<class 'map'>
# python2
Python 2.7.5 (default, Nov 16 2020, 22:23:17)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> res = map(lambda x: x**2, [1,2,3])
>>> res
[1, 4, 9]
>>> type(res)
<type 'list'>
>>>
python Priority of logical operations in
print(not "name" in dicts and dicts["name"]) # in The priority of the > not The priority of the > and The priority of the
// output
PS D:\code\test> & "D:/Program Files/Python37/python.exe" d:/code/test/test.py
False
priority