<jupyter_start><jupyter_text>6.5 TuplesA tuple is a sequence of __immutable__ Python objects. By __immutable__, it means that tuples __CANNOT__ be changed once created. They hold an __ordered__ collection of values which can be of any type.- Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed, as mentioned above unlike lists. Also, tuples use parentheses whereas lists use square brackets.- Tuples can be expanded into variables easily. In assigning values, you may also ommit the paretheses. See examples below:<jupyter_code>tuple1 = ('apple', 'banana', 2012, 1993)
tuple2 = (1, 2, 3, 4, 5 )
tuple3 = "a", "b", "c", "d"<jupyter_output><empty_output><jupyter_text>You may create an empty tuple like this:<jupyter_code>tuple1 = ()<jupyter_output><empty_output><jupyter_text>To write a tuple containing a single value you have to include a comma, even though there is only one value:<jupyter_code>tuple1 = (50,)<jupyter_output><empty_output><jupyter_text>Like string indices, tuple indices start at 0, and they can be sliced, concatenated, and so on. 6.5.1 Accessing Values in a TupleIn accessing values in a tuple, it is also similar to other data types such as lists. Use the square brackets for slicing along with the index or indices to obtain value available at that index.Run the examples below:<jupyter_code>tuple1 = ('P','y','t','h','o','n')

tuple1[0]
tuple1 = ('P','y','t','h','o','n')

tuple1[0:3]<jupyter_output><empty_output><jupyter_text>6.5.2 MethodsSince tuples are immutable (cannot be changed), there are fewer methods available. `len()`> The method `len()` returns the number of elements in the tuple.For example:<jupyter_code># Run the Code
my_tuple = (1, 2, 3, 4, 5)

len(tuple1)<jupyter_output><empty_output><jupyter_text>`count()`> The method `count()` returns count of how many times the `obj` occurs in tuple.For example:<jupyter_code># Run the code
my_tuple = ('apple', 'banana', 'apple', 'orange','banana');

print(my_tuple.count('apple'))<jupyter_output>2<jupyter_text>`index()`> The method `index()` returns the __lowest index__ in a tuple that the `obj` appears.For example:<jupyter_code># Run the code
my_tuple = ('apple', 'banana', 'apple', 'orange','banana');

print(my_tuple.index('banana'))<jupyter_output>1
{'fraction_non_alphanumeric': 0.11805555555555555, 'fraction_numerical': 0.019097222222222224, 'mean_word_length': 6.271293375394322, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '38558', 'license': 'Apache-2.0', 'n_tokens_mistral': 774, 'n_tokens_neox': 731, 'n_words': 280, 'path': 'Beginner_2/6.5 Built-in Standard Data Types - Tuples.ipynb', 'repo_name': 'renzosunico/TrainingNotebookJupyter', 'size': '2304'}