list
Python 2
  • list.sort() or sorted(), sort objects in the list, the types of the objects can be different
  • l = [1, 2, 'Hello', 10]
    
    l2 = sorted(l)
    print(l2) # [1, 2, 10, 'Hello']
    
    l.sort()
    print(l) # [1, 2, 10, 'Hello']
    		
    Python 3
  • list.sort() or sorted(), only support sorting of objects with the same data type
  • l = [1, 2, 'Hello', 10]
    #l2 = sorted(l) # throw TypeError
    l.sort() # throw TypeError
    
    l = [1, 2, 5, 3]
    l2 = sorted(l) # [1, 2, 3, 5]
    l.sort() # [1, 2, 3, 5]