diff --git a/native-datatypes.html b/native-datatypes.html index cb2903a..cad50e9 100755 --- a/native-datatypes.html +++ b/native-datatypes.html @@ -499,6 +499,29 @@ 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.
+
You can use tuples in a boolean context, such as an if statement.
+
+
+>>> def is_it_true(anything):
+... if anything:
+... print('yes, it's true')
+... else:
+... print('no, it's false')
+...
+>>> is_it_true(()) ①
+no, it's false
+>>> is_it_true(('a')) ②
+yes, it's true
+>>> is_it_true((False)) ③
+yes, it's true
+Here’s a cool programming shortcut: in Python, you can use a tuple to assign multiple values at once.