Docsity

Python Programming Programming Programming Notes, Exams of Computer Science

Partial preview of the text

Download Python Programming Programming Programming Notes and more Exams Computer Science in PDF only on Docsity!

Python Programming Programming Programmi

ng Notes

EEI

Python Programming Programming Programmi

ng Notes

Programming in Python

Day School 04 & Practical Session 03 2021/

Python Programming Programming Programmi

ng Notes

ľ"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

Python Programming Programming Programmi

ng Notes

cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.

Python Programming Programming Programmi

ng Notes

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

Python Programming Programming Programmi

ng Notes

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];

Python Programming Programming Programmi

ng Notes

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«;

Python Programming Programming Programmi

ng Notes

Q"cstio⭲ ● Cícatc a t"plc callcd OUSḺ a⭲d assig⭲ Qo"í s"bjcct ⭲amcs i⭲ 2 ⭲ scmcstcí.

Python Programming Programming Programmi

ng Notes

● Syntax : ○ str = "Hi Python !“ # :aíiablc str "si⭲g a PQtko⭲ scíipt

Python Programming Programming Programmi

ng Notes

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.

Python Programming Programming Programmi

ng Notes

str2 = "Hello Python" print (str2) #Using triple quotes str3 = '''''Triple quotes are generally used for represent the multiline or docstring''' print (str3)

Python Programming Programming Programmi

ng Notes

Strings indexing and splitting ● Indexing of the Python strings starts from 0. For example, The string "HELLO" is indexed as given in the figure.

Python Programming Programming Programmi

ng Notes

print (str[3]) print (str[4])

It returns the IndexError because 6th index doesn't exist

print (str[6])

Python Programming Programming Programmi

ng Notes

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.