






































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







































































Day School 04 & Practical Session 03 2021/
ľ"plc i⭲ PQtko⭲ ● A tuple is a collection of objects which ordered and immutable. ● Tuples are sequences, just like lists. ● The differences between tuples and lists are, the tuples
cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.
Acccss :al"cs i⭲ t"plcs ● To access values in tuple, use the square brackets for slicing along with the index or indices to obtain value available at that index
t"p1 = ('pkQsics', 'ckcmistíQ', 1997, 2000); t"p2 = (1, 2, «, 4, 5, 6, 7 ); píi⭲t "t"p1[0]: ", t"p1[0]; píi⭲t "t"p2[1:5]: ", t"p2[1:5];
t"p1[0] = 100; So lct's cícatc a ⭲cw t"plc as rollows t"p« = t"p1 + t"p2; píi⭲t t"p«;
Q"cstio⭲ ● Cícatc a t"plc callcd OUSḺ a⭲d assig⭲ Qo"í s"bjcct ⭲amcs i⭲ 2 ⭲ scmcstcí.
● Syntax : ○ str = "Hi Python !“ # :aíiablc str "si⭲g a PQtko⭲ scíipt
Creating String in Python ● We can create a string by enclosing the characters in single-quotes or double- quotes. Python also provides triple-quotes to represent the string, but it is generally used for multiline string or docstrings.
str2 = "Hello Python" print (str2) #Using triple quotes str3 = '''''Triple quotes are generally used for represent the multiline or docstring''' print (str3)
Strings indexing and splitting ● Indexing of the Python strings starts from 0. For example, The string "HELLO" is indexed as given in the figure.
print (str[3]) print (str[4])
print (str[6])
Slici⭲g i⭲ PQtko⭲ ● A slice object is used to specify how to slice a sequence. You can specify where to start the slicing, and where to end. You can also specify the step, which allows you to e.g. slice only every other item.