Python Programming for Beginners: The Complete Guide to Mastering Python in 7 Days with Hands-On Exercises – Top Secret Coding Tips to Get an Unfair Advantage and Land Your Dream Job! by Philip Robbins

Python Programming for Beginners: The Complete Guide to Mastering Python in 7 Days with Hands-On Exercises – Top Secret Coding Tips to Get an Unfair Advantage and Land Your Dream Job! by Philip Robbins

Author:Philip Robbins [Robbins, Philip]
Language: eng
Format: epub, azw3
Published: 2023-02-02T08:00:00+00:00


Tuples

Even though lists are popular data structures that Python programmers frequently use in their applications, they have several implementation issues. Because all lists created with Python are mutual objects, they are simple to replace, delete, or manipulate.

As a software developer, you may be required to keep immutable lists that cannot be altered in any way. That's why tuples exist. Within Tuples, it is not possible to change initiated elements in any way. When you try to change the content of a tuple, you will get a "Type Error" message.

Program Code:

# Let's create a tuple using Python

t = ('Cat', 'Tree', 'Apple')

print(t)

Output:

('Cat', 'Tree', 'Apple')

In the previous example, we simply initiated a tuple and used a print function to display it on the screen. Tuples, unlike lists, are not represented with square brackets, but rather with parenthesis to distinguish them from lists.

To understand how tuples work, try changing one of the elements in the preceding example and printing the tuple to see what happens.

Program Code:

t = ('Cat', 'Tree', 'Apple')

print(t)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.