diff --git a/native-datatypes.html b/native-datatypes.html index efe1ea0..74bf590 100755 --- a/native-datatypes.html +++ b/native-datatypes.html @@ -499,7 +499,7 @@ AttributeError: 'tuple' object has no attribute 'remove'

Tuples can be converted into lists, and vice-versa. The built-in tuple() function takes a list and returns a tuple with the same elements, and the list() function takes a tuple and returns a list. In effect, tuple() freezes a list, and list() thaws a tuple. -

Assigning Multiple Values At Once +

Assigning Multiple Values At Once

Here’s a cool programming shortcut: in Python, you can use a tuple to assign multiple values at once. @@ -519,8 +519,8 @@ AttributeError: 'tuple' object has no attribute 'remove'

This has all kinds of uses. I often want to assign names to a range of values. In C, you would use enum and manually list each constant and its associated value, which seems especially tedious when the values are consecutive. In Python, you can use the built-in range() function with multi-variable assignment to quickly assign consecutive values.

->>> (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)  
->>> MONDAY                                                                       
+>>> (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)  
+>>> MONDAY                                                                       
 0
 >>> TUESDAY
 1