#----------------------------- 1- Creating a Tuple -------------------------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship")
print(company)
#----------------------------- 2- Packing & Unpackinga Tuple -----------------------
# Packing values into a tuple
company = ( "WebGapp", "Python", "Internship")
# Unpacking a tuple into variables
name , language , type = company
print(name)
#----------------------------- 3- Adding two Tuples ----------------------------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship")
comapny2 = ("TCS", "Java", "Internship")
# Combining two tuples
tup = company + comapny2
print(tup)
#----------------------------- 4- Iterating through Tuple --------------------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship")
# Iterating through a tuple using a for loop
for web in company:
print(web)
#----------------------------- 5- Immutable in Tuple ----------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship")
# Attempting to modify a tuple ( Cannot modify tuples )
company[1] = "Java" # TypeError: 'tuple' object does not support item assignment
#---------------------------- 6- Slicing the Tuple -------------------------
# Slicing a tuple to get a sublist
company = ( "WebGapp", "Python", "Internship")
numbers = (1, 2, 3, 4, 5)
tuple = numbers[1:4]
tuple2 = company[0:2]
print(tuple)
print()
print(tuple2)
#--------------------------- 7- Checking elements in Tuple --------------------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship")
# Checking if an element exists in a tuple
if 'Python' in company:
print("Python is in the tuple")
#-------------------------- 8- Simple built in functions in Tuple ------------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship","Python")
# Finding the length of a tuple
length = len(company) # 3
print("length :" ,length)
# Counting occurrences of an element in a tuple
count = company.count("Intership") # 1
print("Count: ",count)
# Finding the index of an element in a tuple
index = company.index("Python") # 2
print("Position",index)
#--------------------------- 9- Acessing Tuple ---------------------------------------
# Creating a tuple
company = ( "WebGapp", "Python", "Internship")
# Accessing tuple elements by index\
index = company[0]
print(index)
#--------------------------- 10- Nested Tuple ---------------------------------------
# Creating a nested tuple
company = ("Webgapp", "Python", ("Week", "month"), ("Basic Knowledge", "Project"))
# Accessing elements of the nested tuple
name = company[0]
course = company[1]
duration = company[2][1]
outcome = company[3][1]
# Displaying the information
print("Name:", name)
print("Courses :", course)
print("Course Duration :", duration)
print("Course outcome : ", outcome)