Functions explaination

when sort() and sorted() are used?

2 Likes

sort function changes the list its being used on. while the sorted function makes another sorted list and assigns to the variable we have given
image

2 Likes

@mekala.akhil2468

The sort() function returns nothing and changes the original sequence.

Syntax - Sort() :
list_name . sort() → (It will arrange the elements in ascending order)

The sorted() function creates a new sequence type containing a sorted version of the given sequence

Syntax - Sorted() :
sorted( iterable, key, reverse ) → ( Parameters: sorted takes three parameters from which two are optional )

Note:
sort() can only sort the list, but sorted() can sort list, tuple, or any other sequence type.