Python tuple program to slice a tuple

In this python tuple program, we will slice a tuple.

Steps to solve the program
  1. Create a tuple.
  2. Slice the given tuple using tuple_name[start_index:end_index].
  3. Print the output.
				
					tup = (5,7,3,4,9,0,2)
print("Original tuple: ",tup)
print(tup[:3])
print(tup[2:5])
				
			

Output :

				
					Original tuple:  (5, 7, 3, 4, 9, 0, 2)
(5, 7, 3)
(3, 4, 9)
				
			

remove an item from a tuple.

find an index of an element in a tuple.

Python tuple program to remove an item from a tuple

In this python tuple program, we will remove an item from a tuple.

Steps to solve the program
  1. Create a tuple.
  2. Now convert that tuple to a list using list().
  3. Remove the element from the list.
  4. Again convert the list to a tuple using tuple().
  5. Print the output.
				
					tup = ('p','y','t','h','o','n')
print("Original tuple: ",tup)
l = list(tup)
l.remove('h')
tup = tuple(l)
print("After removing an element: ",tup)
				
			

Output :

				
					Original tuple:  ('p', 'y', 't', 'h', 'o', 'n')
After removing an element:  ('p', 'y', 't', 'o', 'n')
				
			

convert a list into a tuple and multiply each element by 2.

program to slice a tuple.

Convert a list into a tuple and multiply each element

In this pythin tuple program, we will convert a list into a tuple and multiply each element.

Steps to solve the program
  1. Create a list and an empty list.
  2. Use for loop to iterate over elements in the list.
  3. Multiply each element by 2 and add it to the empty list.
  4. Now convert the new list to a tuple using tuple().
  5. Print the output.
				
					list1 = [12,65,34,77]
list2 = []
for ele in list1:
    a = 2*ele
    list2.append(a)
    
tup = tuple(list2)
print("Origianl list: ",list1)
print("After multiplyting by 2: ",tup)
				
			

Output :

				
					Origianl list:  [12, 65, 34, 77]
After multiplyting by 2:  (24, 130, 68, 154)
				
			

remove an item from a tuple.

Python tuple program to multiply adjacent elements of a tuple

In this python tuple program, we will multiply adjacent elements of a tuple.

Steps to solve the program
  1. Create a tuple and an empty list.
  2. Create a tuple having adjacent elements as a tuple inside of a tuple using zip(tup,tup[1:]).
  3. Use for loop to iterate over this tuple.
  4. Now get the product of the adjacent element and add it to the empty list.
  5. Convert the list back to the tuple using tuple().
  6. Print the output.
				
					tup =  (1,2,3,4)
list1 = []
for a,b in zip(tup,tup[1:]):
    c = a*b
    list1.append(c)
tup = tuple(list1)
print("Multiplying adjacent elements: ",tup)
				
			

Output :

				
					Multiplying adjacent elements:  (2, 6, 12)
				
			

create a tuple having squares of the elements from the list.

Python Projects For Beginners

This article has common Python Projects for beginners, which have all categories of projects from basic to advanced.

Basic Level Projects:

  • Basic Calculator
  • Show Calendar
  • Convert pdf to text
  • Convert image to pdf
  • Convert dictionary to JSON
  • Convert JPEG to PNG
  • Convert JSON to CSV
  • Convert XML to JSON
  • Convert book into audiobook 
  • Decimal to binary convertor and vice versa
  • DNS Records
  • Encrypt and decrypt text
  • Extract zip files
  • Fetch HTTP status code
  • Fetch open ports
  • Hashing passwords
  • Merge csv
  • Merge pdf
  • QR code generator
  • Random password generator

Intermediate Level Projects:

  • Capture screenshot
  • Calculate age
  • Chrome Automation
  • Convert numbers into words
  • Script to encrypt files and folders
  • Article Downloader
  • Duplicate file remover
  • Email GUI
  • Email verification
  • Facebook dp downloader
  • Get wifi password
  • Github repo automation
  • Image to speech
  • Language Translator
  • Password manager
  • Plagiarism checker
  • Python image compressor
  • Send an email with a python
  • Send mail from CSV
  • Set alarm
  • URL shortener

Advance Level Projects:

  • Auto birthday wisher.
  • Auto Backup.
  • Auto-fill the google form.
  • Automate Facebook bot.
  • Automatic certificate generator.
  • Automatic Facebook login
  • Calculator GUI
  • Calendar GUI
  • CLI todo
  • Simple Stopwatch
  • Dictionary GUI
  • Easy cartoonify the image
  • Video Player
  • Extract text from PDF
  • Gesture control media player
  • Google meeting bot
  • Image to sketch
  • Noise reduction script
  • Password manager GUI
  • PDF reader with voice
  • Quote scraper
  • Screen recorder
  • Speech to text
  • Text to speech
  • Text editor
  • Voice Translator
  • Video to audio converter

Create a tuple having squares of the elements from the list

In this python tuple program, we will create a tuple having squares of the elements from the list.

Steps to solve the program
  1. Create a tuple and convert it to a list using list().
  2. Use for loop to iterate over elements in the list.
  3. Find the index of the element using index().
  4. Get the square of the element.
  5. Now replace the square with the old element in the list.
  6. Now convert that list to a tuple using tuple().
  7. Print the output.
				
					tup = (1,3,5,7,6)
print("Origianl tuple: ",tup)
a = list()
for i in list(tup):
    b = i**2
    a.append(b)
tup = tuple(a)
print("After sqauring elements: ",tup)
				
			

Output :

				
					Origianl tuple:  (1, 3, 5, 7, 6)
After sqauring elements:  (1, 9, 25, 49, 36)
				
			

multiply adjacent elements of a tuple.

Python tuple program to add a list in the tuple

In this python tuple program, we will add a list in the tuple.

Steps to solve the program
  1. Create a list and a tuple.
  2. Convert the tuple into a list using list() and add another list to it using+ “.
  3. Now convert the combined list to a tuple using tuple().
  4. Print the output.
				
					list1 = [12,67]
tup = (6,8,4)
result = tuple(list(tup) + list1)
print(result)
				
			

Output :

				
					(6, 8, 4, 12, 67)
				
			

check whether an element exists in a tuple or not.

find sum of elements in a tuple.

Check whether an element exists in a tuple or not

In this python tuple program, we will check whether an element exists in a tuple or not.

Steps to solve the program
  1. Create a tuple.
  2. Use an if-else statement to check whether an element exists in the tuple.
  3. Print True if the element exists in the tuple else print False.
				
					tup = ('p','y','t','h','o','n')
if 'p' in tup:
    print("True")
else:
    print("False")
				
			

Output :

				
					True
				
			

get the 2nd element from the front and the 3rd element from the back of the tuple.

add a list in the tuple.

Python tuple program to get elements from the tuple using indexing

In this python pandas program, we will get elements from the tuple using indexing.

Steps to solve the program
  1. Create a tuple.
  2. Get the 2nd element from the front using tuple_name[1].
  3. Get the 3rd element from the last using tuple_name[-3].
  4. Print the output.
				
					tup = ('s','q','a','t','o','o','l','s')
print("2nd element from the front in the String: ",tup[1])
print("3rd element from the last in the String: ",tup[-3])
				
			

Output :

				
					2nd element from the front in the String:  q
3rd element from the last in the String:  o
				
			

convert a tuple into a string.

check whether an element exists in a tuple or not.