0% found this document useful (0 votes)
4 views5 pages

Python Assingment 2

The document contains a series of Python exercises demonstrating string and list operations, including concatenation, repetition, and sorting. It includes examples of manipulating tuples and lists, as well as basic functions like min and max. Each exercise is presented with code snippets and their outputs for clarity.

Uploaded by

shifa1795sahota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Python Assingment 2

The document contains a series of Python exercises demonstrating string and list operations, including concatenation, repetition, and sorting. It includes examples of manipulating tuples and lists, as well as basic functions like min and max. Each exercise is presented with code snippets and their outputs for clarity.

Uploaded by

shifa1795sahota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSINGMENT 2

EX:1

>>> x='python'

>>> x*9

'pythonpythonpythonpythonpythonpythonpythonpythonpython'

>>> y='mathematics'

>>> y*9

'mathematicsmathematicsmathematicsmathematicsmathematicsmathematicsmathematicsmathem
aticsmathematics'

EX:2

>>> string1='Hello'

>>> string2=' World!'

>>> string1+string2

'Hello World!'

>>> string1='Good'

>>> string2='Morning'

>>> string1+string2

'GoodMorning'

EX:3

>>> x='LATEX'

>>> x*11

'LATEXLATEXLATEXLATEXLATEXLATEXLATEXLATEXLATEXLATEXLATEX'

>>> y='MATLAB '

>>> y*11

'MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB
'

EX:4

>>> list1=[15,20,25,30,35,40]

>>> list2=[7,14,21,28,35,42]
>>> list1+list2

[15, 20, 25, 30, 35, 40, 7, 14, 21, 28, 35, 42]

>>> 9*list1

[15, 20, 25, 30, 35, 40, 15, 20, 25, 30, 35, 40, 15, 20, 25, 30, 35, 40, 15, 20, 25, 30, 35, 40, 15, 20, 25,
30, 35, 40, 15, 20, 25, 30, 35, 40, 15, 20, 25, 30, 35, 40, 15, 20, 25, 30, 35, 40, 15, 20, 25, 30, 35, 40]

>>> 7*list2

[7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35,
42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42]

EX:5

>>> tuple=(5,-3,0,1,6,-6,2)

>>> sorted(list(tuple))

[-6, -3, 0, 1, 2, 5, 6]

>>> tuple=[5,-3,0,1,6,-6,2]

>>> tuple.reverse()

>>> print(tuple)

[2, -6, 6, 1, 0, -3, 5]

>>> tuple=[5,-3,0,1,6,-6,2]

>>> revtuple=tuple[::-1]

>>> print(revtuple)

[2, -6, 6, 1, 0, -3, 5]

EX:6

>>> x=(49,17,23,54,36,72)

>>> sorted(list(x))

[17, 23, 36, 49, 54, 72]

EX:7

>>> M=[1,2,3,4]

>>> len(M)

>>> L="XYZ"+"PQR"

>>> print(L)

XYZPQR

>>> s='make in india'


>>> (s[:7])

'make in'

>>> (s[:9])

'make in i'

EX:8

>>> list1=[5,10,15,20,25,30]

>>> list2=[7,14,21,28,35,42]

>>> list1+list2

[5, 10, 15, 20, 25, 30, 7, 14, 21, 28, 35, 42]

>>> 3*list1

[5, 10, 15, 20, 25, 30, 5, 10, 15, 20, 25, 30, 5, 10, 15, 20, 25, 30]

>>> 5*list2

[7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35, 42, 7, 14, 21, 28, 35,
42]

>>>EX:9

>>> student_list=['a',1,'b',2,'c',3,'d',4,'e',5]

>>> print(student_list)

['a', 1, 'b', 2, 'c', 3, 'd', 4, 'e', 5]

EX:10

>>> a=[7,8,71,32,49,-5,7,7,0,1,6]

>>> min(a)

-5

>>> max(a)

71

EX:11

>>> x='complex Number'

>>> x*7

'complex Numbercomplex Numbercomplex Numbercomplex Numbercomplex Numbercomplex


Numbercomplex Number'

>>> y='Real Number'

>>> y*7

'Real NumberReal NumberReal NumberReal NumberReal NumberReal NumberReal Number'


EX:12

>>> string1='India Won'

>>> string2=' World Cup'

>>> string1+string2

'India Won World Cup'

>>> string1='God'

>>> string2=' is Great'

>>> string1+string2

'God is Great'

EX:13

>>> S='MATHEMATICS'

>>> S[2]

'T'

>>> S[5]

'M'

>>> S[8]

'I'

EX:14

>>> L=[16,3,5,48,2,4,5,6,78,12,5,6,24]

>>> min(L)

EX:16

>>> S=[1,2,3,4,5,6,7,8,9]

>>> S.reverse()

>>> print(S)

[9, 8, 7, 6, 5, 4, 3, 2, 1]

EX:17

>>> S=[3,4,5,6,7,8,9,10,11,12,13]

>>> S.reverse()

>>> print(S)

[13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3]


EX:18

>>> tuple='I am Indian'

>>> tuple[2]

'a'

EX:19

You might also like