LEARN PYTHON PROGRAMMING FOR BEGINNERS: A beginner's guide comprehending python. Develop your programming skills and learn all the tricks with this crash course. by Willard D. Sanders
Author:Willard D. Sanders [Sanders, Willard D.]
Language: eng
Format: azw3
Published: 2020-10-01T00:00:00+00:00
Youâll discover how to manage and handle errors and exceptions effectively.
Python Tuples
In Python, Tuples are collections of data types that cannot be changed but can be arranged in a specific order. Tuples allow for duplicate items and are written within round brackets, as shown in the syntax below.
Tuple = (âstring001â, âstring002â, âstring003â)
print (Tuple)
Tuples are similar to lists and creating them is quite simple, one has to put commas to separate values and these values can also be enclosed in parenthesis. For example: tup1 = (âchemistryâ, âphysicsâ, 1998, 2000); tup2 = (7, 8, 9); tup3 = âxâ, âyâ, âzâ ; Listed below are some of the basic features of tuple:
a) For writing an empty tuple two parentheses are used â tup1 = ();
b) Even of the tuple contains a single value one has to include commaâtup1 = (50,);
c) The indices in tuple start with at 0 and slicing can also be done.
d) Square brackets are used to access values in tuples
e) One cannot change or update the values in tuples
f) Removing the tuple element is not possible; however one can use del to remove the entire tuple.
g) All general operators can be used There are few built-in tuples like:
For comparing different elements - cmp(tuple1, tuple2)
To find the total length of tuple -len(tuple)
Converting a list to tuple â tuple(seq)
Find maximum valueâmax(tuple)
Minimum value â min(tuple)
Similar to the Python List, you can selectively display the desired string from a Tuple by referencing the position of that string inside the square bracket in the print command as shown below.
Tuple = (âstring001â, âstring002â, âstring003â)
print (Tuple [1])
OUTPUT â (âstring002â)
The concept of negative indexing can also be applied to Python Tuple, as shown in the example below: Tuple = (âstring001â, âstring002â, âstring003â, âstring004â, âstring005â)
print (Tuple [-2])
OUTPUT â (âstring004â)
You will also be able to specify a range of indexes by indicating the start and end of a range. The result in values of such command on a Python Tuple would be a new Tuple containing only the indicated items, as shown in the example below:
Tuple = (âstring001â, âstring002â, âstring003â, âstring004â, âstring005â, âstring006â)
print (Tuple [1:5])
Output
(âstring002â, âstring003â, âstring004â, âstring005â)
* Remember the first item is at position 0 and the final position of the range, which is the fifth position in this example, is not included.
You can also specify a range of negative indexes to Python Tuples, as shown in the example below: Tuple = (âstring001â, âstring002â, âstring003â, âstring004â, âstring005â, âstring006â)
print (Tuple [-4: -2])
Output â (âstring004â, âstring005â)
* Remember the last item is at position -1 and the final position of this range, which is the negative fourth position in this example is not included in the Output.
Unlike Python lists, you cannot directly change the data value of Python Tuples after they have been created. However, conversion of a Tuple into a List and then modifying the data value of that List will allow you to subsequently create a Tuple from that updated List. Letâs look at the example below: Tuple1 = (âstring001â, âstring002â, âstring003â, âstring004â, âstring005â, âstring006â) List1 = list (Tuple1)
List1 [2]
Download
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.
API Testing and Development with Postman by Dave Westerveld(3616)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2614)
Software Architecture for Busy Developers by Stéphane Eyskens(2320)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1884)
Machine Learning for Algorithmic Trading by Stefan Jansen(1628)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1457)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1402)
Cloud Native with Kubernetes by Alexander Raul(1374)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1346)
Software Architecture Patterns for Serverless Systems by John Gilbert(1338)
Practical Node-RED Programming by Taiji Hagino(1336)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1312)
Delphi Programming Projects by William Duarte(1296)
Mastering React Test-Driven Development by Daniel Irvine(1289)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1253)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1243)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1235)
