# tuples are immutable
# initialize tuple
scores = (10, 20, 30)
# check if 10 is in scores tutple
print(10 in scores)
# print all scores in tuple
for score in scores:
print(scores)
# print length of tuple
print(len(scores))
# print scores reversed
print(tuple(reversed(scores)))
# print scores reversed
print(scores[::-1])
# print first score by index
print(scores[0])
# print first two scores
print(scores[0:2])
# print tuple
thistuple = ("apple",)
print(type(thistuple))
#NOT a tuple
thistuple = ("apple")
print(type(thistuple))
from collections import namedtuple
Point = namedtuple('Point', 'x y')
p = Point(1, y=2)
p[0]
# 1
p.x
# 1
getattr(p, 'y')
# 2
p._fields # Or: Point._fields
# ('x', 'y')
# Change Value In Tuple :-
friends = ("Mido", "Lucifer", "Abdelrhman")
# Example => Wanna Change ( Abdelrhman ) To ( Aiiob );
# First We Need Transformation From Tuple To List ,
# We Need To Create Variable With Any Name
# After This We Use list() Function
oneName = list(friends)
# After This We Need Change The Value ,
oneName[-1] = "Aiiob"
# After This We Need Transformation From List To Tuple ,
# We Use tuple() Function
friends = tuple(oneName)
# And We Done (:
a=(1,2,3,4)
print(a[-3])
tuple = ("Facebook", "Instagram", "TikTok", "Twitter")
tupel python
# Creating an empty Tuple
Tuple1 = ()
print("Initial empty Tuple: ")
print(Tuple1)
# Creating a Tuple
# with the use of string
Tuple1 = ('Geeks', 'For')
print("
Tuple with the use of String: ")
print(Tuple1)
# Creating a Tuple with
# the use of list
list1 = [1, 2, 4, 5, 6]
print("
Tuple using List: ")
print(tuple(list1))
# Creating a Tuple
# with the use of built-in function
Tuple1 = tuple('Geeks')
print("
Tuple with the use of function: ")
print(Tuple1)
#!/usr/bin/python
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print "tup1[0]: ", tup1[0];
print "tup2[1:5]: ", tup2[1:5];