[Tutor] If tuple cannot be sorted, then why sorted() on a tuple is fine?

Alan Gauld alan.gauld at yahoo.co.uk
Wed Aug 2 16:07:00 EDT 2017


On 02/08/17 20:01, C W wrote:

> I am a little confused about why Tuple can be sorted.
> 
> Suppose I have the following,
> 
>> aTuple = (9, 3, 7, 5)
>> sorted(aTuple)
> [3, 5, 7, 9]

sorted() returns a new object.
The original tuple has not been changed
 - print aTuple to confirm this.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list