{"id":16500,"date":"2021-08-12T09:33:25","date_gmt":"2021-08-12T04:03:25","guid":{"rendered":"https:\/\/python-programs.com\/?p=16500"},"modified":"2021-11-22T18:38:29","modified_gmt":"2021-11-22T13:08:29","slug":"python-program-to-remove-elements-from-a-tuple","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-remove-elements-from-a-tuple\/","title":{"rendered":"Python Program to Remove Elements from a Tuple"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check if all Characters of String are Alphanumeric or Not<\/a> A tuple is an immutable list of objects. That means the elements of a tuple cannot be modified or changed while the program is running.<\/p>\n The elements from any tuple can be removed by slicing the tuple.<\/p>\n Slicing:<\/strong><\/p>\n Slicing is a Python feature that allows you to access chunks of sequences such as strings, tuples, and lists. You may also use them to change or remove elements from changeable sequences like lists. Slices can also be used on third-party objects such as NumPy arrays, Pandas series, and data frames.<\/p>\n Slicing allows for the creation of code that is clear, concise, and readable.<\/p>\n Given a tuple, the task is to remove elements from a given tuple.<\/p>\n Examples:<\/strong><\/p>\n Example 1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to remove Elements from a Given Tuple<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Check if all Characters of String are Alphanumeric or Not Tuple in Python: A tuple is an immutable list of objects. That means the elements of a tuple cannot be modified or changed while the program is running. The elements from any tuple can be …<\/p>\n
\nTuple in Python:<\/strong><\/p>\nGiven Tuple = (14, 32, 16, 85, 47, 65)<\/pre>\n
The above given tuple after removal of { 3 } Element = (14, 32, 16, 47, 65)<\/pre>\n
Given Tuple = (12, 3, 48, 98, 23, 64, 75, 10, 56)<\/pre>\n
The above given tuple after removal of { 5 } Element = (12, 3, 48, 98, 23, 75, 10, 56)<\/pre>\n
Program to Remove Elements from a Tuple<\/h2>\n
Method: Using Slicing Operator (Static input)<\/h3>\n
\n
# Give the tuple as static input and store it in a variable.\r\ngven_tup = (14, 32, 16, 85, 47, 65)\r\n# Give the number as static input and store it in another variable.\r\nnum = 3\r\n# Do out the Slicing from '0 ' to given 'n-1' and store it in a variable.\r\nfst_part = gven_tup[:num]\r\n# Again do out the Slicing from 'n+1' to given length of tuple (till end) and\r\n# store it in another variable.\r\nsecnd_part = gven_tup[num+1:]\r\n# Add the above two slicing parts using '+' operator and store it in a variable.\r\ngven_tup = fst_part + secnd_part\r\n# Print the final tuple after removal of given elements from the above given tuple.\r\nprint(\r\n \"The above given tuple after removal of {\", num, \"} Element = \", gven_tup)\r\n<\/pre>\n
The above given tuple after removal of { 3 } Element = (14, 32, 16, 47, 65)<\/pre>\n
\n