How to Get First & Last Elements From a Tuple in Python | EP-14 Get First & Last Elements from Tuple

Subscribers:
27,900
Published on ● Video Link: https://www.youtube.com/watch?v=oMyo7tYObLE



Duration: 16:05
110 views
5


1. Get First and Last Elements from a Tuple Using Indexing
"""We can use indexing to access the first and last elements of the tuple.
Python indexing starts at 0 for the first element and -1 for last element."""
my_tuple = (10,20,30,40,50)
first_element = my_tuple[0]
last_element = my_tuple[-1]
print(" first element:",first_element)
print("last element:",last_element)

method 2:
my_tuple = tuple(map(int,input("enter the elements").split()))
print(my_tuple)
first = my_tuple[0]
last = my_tuple[-1]
print("first_element",first)
print("last_element",last)

2. Get First and Last Elements from a Tuple Using Tuple Unpacking
"""using *_ clearly indicates that you intend to capture and discard
(in the case of unpacking) or store a collection of remaining arguments."""
my_tuple3 = (1,2,3,4)
first_element,*_,last_element = my_tuple3
print("first_element",first_element)
print("last_element",last_element)


3. Get First and Last Elements from a Tuple Using Slicing
my_tuple4 =("a","b","c")
first =my_tuple4[:1][0]
last =my_tuple4[-1]
print("first_element",first)
print("last_element",last)

#PythonTutorials #PythonBasics #PythonProgramming #PythonTips #LearnPython #PythonForBeginners #Coding #Programming #TuplesInPython #python #pythonbeginner #pythontips #tuple #tuplemanipulation #getfirstelement #getlastelement #coding #programming #tutorial

Connect With Us:
—————————————
➡️ Website: https://www.cybrosys.com/
➡️ Email: info@cybrosys.com
➡️ Twitter:   / cybrosys  
➡️ LinkedIn:   / cybrosys  
➡️ Facebook:   / cybrosystechnologies  
➡️ Instagram:   / cybrosystech  
➡️ Pinterest:   / cybrosys  




Other Videos By Cybrosys Technologies


2024-07-22How to Scan CV Using AI in Odoo 18 | Artificial Intelligence to Scan CV | New Features in Odoo 18
2024-07-22How to Create Approval Type in Odoo 17 Approval | What are the Different Approval Types in Odoo 17
2024-07-21How to Count Records Using Search Count in Odoo 17 | Odoo 17 Development Tutorials | Search_Count()
2024-07-21How to Restore Project History in Odoo 18 | Latest Features in Odoo 18 | New Features in Odoo 18
2024-07-18How to Configure Inventory Operation Types in Odoo 17 |What are Warehouse Operation Types in Odoo 17
2024-07-18How to Take User Input in a List in Python | EP-17 Taking Integer Input in Python List | Python List
2024-07-17What is List in Python | EP-16 List in Python | How to Create List in Python | Lists Functions
2024-07-17How to Manage Manufacturing Backorders in Odoo 17 | Odoo 17 Manufacturing Tutorials
2024-07-16How to Configure Re Sequence in Odoo 17 Accounting App | Odoo 17 Accounting | Functional Tutorials
2024-07-16How to Handle Missing Keys in Python Dictionaries | Ep-15 Handling Missing Keys in Dictionaries
2024-07-15How to Get First & Last Elements From a Tuple in Python | EP-14 Get First & Last Elements from Tuple
2024-07-14How to Create Invoice Upon Email in Odoo 17 Accounting App | Odoo 17 Functional Tutorials
2024-07-14How to Find & Print the Size of a Tuple in Python | EP-13 Find the Size of a Tuple | What is Tuple?
2024-07-11How to Create a Product in Odoo 18 POS | Odoo 18 Latest Features | Odoo 18 New & Upcoming Features
2024-07-11How to Sell Your Products in Odoo 17 Website App | Odoo 17 Website Tutorials | Functional Tutorials
2024-07-10What is Set in Python | EP-12 Sets in Python | How to Create Set in Python | Free Python Tutorials
2024-07-10Revamp in Product View in Odoo 18 | Latest Features in Odoo 18 | New & Upcoming Features in Odoo 18
2024-07-09How to Create an App Using Odoo 17 Studio | Customize App Using Odoo 17 Studio | Odoo 17 Tutorials
2024-07-08How to Add Language Translation in Odoo 17 | Internationalization | Adding Translation in Odoo 17
2024-07-08What is Tuple Operations in Python | EP-11 Tuple Operations in Python | Basic Tuple Operations
2024-07-08Latest Features in Odoo 18 | Upcoming Features in Odoo 18 | New Features in Odoo 18| EP-1 Tech Tonic



Tags:
Python
Python Tutorials
Python Tuples
Learn Python
Python Basics
Python Programming
How to Get First and Last Elements from a Tuple
Python Tips
Programming
Python for Beginners
Tuple Basics
Python Coding Tips
Python Guide
Extracting Elements from Tuples
Python Learning
Programming Tutorials
Python Video
Python Course
PythonProgramming
PythonForBeginners
Tuple
GetFirstElement
GetLastElement
DataManipulation
Indexing
NegativeIndexing
EfficientCode
PythonTutorials