Python Imp 1 - Saicharan Pagidi
Python Imp 1 - Saicharan Pagidi
j1nmm,'rir
k· j p,·~ ,r, ·,
Python Important Questions
~-
Unit-1
Short Answers
5. Which Python types are sequences, and how do they differ from mapping?
double and
6 G,ve a not on each of the below Python language constructs: (i) quotes (single,
triple) (ii) multiline statements (iii) indentation
Long Answers
script b)List
1. How to declare and call functions in Python programs? Illustrate with an example
and explain few most commonly used built-in types in python.
deals with
2. Summarize various operators, built-in functions and standard library modules that
Python's numerictype.
3. Make Comparision of Internal types Ellipsis and Xrange?
4. List Built-in Methods used for string comparision?
an
5. What is lambda function? What are the characteristics of a lambda function? Give
example
6. Write about the concept of scope of a variable in a function.
Unit-2
Short Answers
Long Answers
on and
1. Explain the following file built-in functions and method with clear syntax, descripti
illustration: a) open() b) file() c) seek() d) tell() e)read()
lustrate
2. How does try-except statement work? Demonstrate with an example python code's)ll
the concept of importing module attributes in python scripts.
d line
3. Writ~ python program to append the contents of second file to first file use comman
arguments?
4. With example discuss except statement with multiple exception?
5 wh,it ,ltl' romm;1111l lino ;11qt111wnts nnd oxpl;iin II with an exc1mple?
G Expl,1in input ,rnd output mothods of Ille?
Unit-3
Short Answers
1 Summarize the purpose of pipe and dot symbols used for pattern matching.
2. Explain the basic functionality of match( ) function.
3 Differentiate between Lock and Rlock Objects?
4. Formulate Regular expression pattern for the following t Word which starts with 'the and
matches words only with 'the' and string contains the but not begin with 'the'
5. Explain the differences between process and thread?
6. Explain methods of threading module.
Long Answers
1. Examine how python supports regular expressions through the 're' module with brief
introduction and various built-in methods related to it:
2. What is the motivation behind paralleJism and state how python achieves parallelism ) Explain
briefly about thread and threading module objects in Python.
3. Write a program to demonstrate multi threaded mechanism provided by thread module in
python
4. What are regular expressions? How to find whether an email id entered by user is valid or
not using Python're' module.
5. Explain the syntax of creating a thread with examples? And explain about light weight
process
6. Difference between thread and threading module?
Unit-4
Short Answers
1. Consider a Python GU I program that produces a window with thu fr,llrJt✓ 1ng wJgr:ts u rng
python code a) A button to retrieve the next value in th:1t list(1f there 1s r,n,JJ Tl-11s button 18
displayed if there is no next value in the listb) A label to d1spl;iy the numbe:ir rJf the 1tern
being displayed and the total number of items
2. Give an overview and demonstration of building web applications using p1t~10n s Vl' module
'-3' Create a web crawler as an advanced web client using python module
4. Explain the Architecture of CGI?
5. What is url <Explain about URL Methods?
V. Discuss about URLLIB2 module?
Unit-5
Short Answers
Long Answers
1. What is a cursor object? Explain various methods and attributes of cursor object.b)What do
you mean by a constructor? List and describe various constructors used for converting to
different data types.
2. SQLalchemy provides more flecibility in issuing raw 'sql' sunstantiate this statement?
3. Discuss the following commonly used query methods:
Offset(), filter_ by(),orderby()
4. Describe in detail about Python SQLAlchemy ORM with a case study of Employee role
database.
5. Explain about ORM and its advantages?
6. W hat are DB-API Module Attributes?
Ul\l 11 - I
1) H <>.i: < Ct<J :J --focw °fPL, coJ, o () < Nh eN< f ~ 1f,o I) u. mo-n po pv.J,
A) o... //,Jt.b ~l':,l,'c.o.:h'oni
b Du.kt-op 9 u, °'fFlu::a-hons:
c ~l)..,tin~<.t o.ppli'c_o...-hon<;:,
d 't'mo.~e fYoc.<?ccin~ o..pplic..a._·t ionr
e. ~oj--l WO-iYq_ De.ve.lo pm eFl+-
-f Do.Jo. b~ e o..c c U(,.
i • 9o..m e_ De. v e lop TY) e_ nt .
n o.+L,(JY e
L,c.t u' c.-hrved \f) [ J 1 • Tu-plu OJre ~tt,,ye_J ti) ( )
:/
V)l\::>e.c.+e.d c,h~e..~ ~, .Tn +upl~, i!-- 0. hOJYd to
g, !he LL()
-+y Pe_ W,
u.-nne c~CJJJ!j· P:j~on VOJY~ oblu do nob ne..e_o\
e.:~\;dt- de.c..lOJYo.tiof) +o 'Yuvv,u mUYJD"':J ~po.c.e..
Th e. d e. c.. l ON a:b o() h o..p pUJ .c. o.u +o rna:b ux 11_:J w he.n jou
0 == 10
6 :- 12. . ('
c_ -= •• h. e. l lo"
p'Y1nt Co):), c.)
p:Jtl'io() &\lloN( ~OU -Iv O.J/4•i r 0. !i05l< v,::,.\u,_ -to .!.<VUYo../
.fx:-
o. ::: b ~ c. ~ I
4) V.Jhi,h p~tf'..on objecb. OJ'rt lmrn1J.+obl, ? [-,_pla.u1 1,v,t~
{~ Clrfl pIe g. .
--tLlple t == Co,, 1
1, 3,)
+u.pltr[ol~ 4-
p·n r,t [-l up/e._ I)
#--£"r"f O"l Co u.-l-pu t)
~ :- -=# r +'Yi nC] t
~IC t1 OnOJ'I ~
~) Ci; v, ()_ noh on Wth D~ #;, !:,,low p~tkon /Ofl~ U D ·r
c.on d -, ud, : (i J 9ct oh t ( "n':J 1, , cloubl, ~ -h ip I,)
(11) rnl.). t+;L;ne. ~+o.+~me.nh l_l°i.1) indU')toJ.,on .
A) L') qu.ot(!..t :-
~\,ol:-a:hon t~N1bol,,, OJY< l).),<d +o m,0--t, ~-1:"'l"'j obj'c.t-
in Niton . P~tlio<l ..,-,,_wcf J'--'- rn,f , dou bl, ; -h-ipk
'tu.Dhc1 :l
i hi n t • H", n :l Li hj'{o.L. =• vcm H e.n b~
V') t Lo n gu o. i •~u. ma ot c.h DJYO. ct mt til ti n 'J l , 9u..oh-1
(' hdlo' 1 , doubl, q,l.l.O+CA (" J,,.,llo") o'Y -hipl• 9,u.ob...<
..r')\. '-
">'>> ~ - Li~ t = [' ' \
2,_ I 5 \
.. . ,4,r\
-. . J
?7'> p'Y1nt[rn:J - Lit+)
~ +p½r-
[ ,,2, s ,4, C]
. Iciii) gytl';on incl rnto.h()n:
1
l'- Io.n~ o / fR, h, 3h I,"' I l;,y "~' e>mrY1i nq lo.n')"" J' \ I, k1
C , C.-t -t , C # u ~ t b'f 0. c. e <. t 1 -I o m OJY k o b I or k o b r n,. . L,
Py~on doei. ir VIO. l(")dH')[o.tlor) . A t.orl~ block whid
-,-,pnl«-nt. -tkL bod_'.:} o~ o. -/w1di on O'Y o. lo op f.:.e~1ni
~v 1,tg t e.. , n cl e..rrt o. ti on o..ri ~ e.r, d ( ~v it R f~ , -f, "' d-
(J.J') rncl e..nte..d Ll n e.. •
~n9 Of)~WQ/Y ~
1)1 --t-lolAJ -+-o d e.dOJYt o.nd c.o..11 -fW)c tion (._ LI") p~t~on r 09"'f om
--r'YO 2 ,I)<:.,_1: bO D \ b'::l t U bjU)_'< "I 0-1_:\ rf\ VY1 D"f':J Vi <2-W ·
1 1
I 1
obj~ct ·
v()JYiov-A optNo.-1-o-v .t , btJ.i It - in +,enc. -hons ;
Ll b'Y OJ'(~ Mod L,l. I u. --tfi oJ d ~ c,._,Ll w i~ pj tfi on\
() l,UY) VY j C. ~ pt.. •
p,,) p':lit; on op v,- o..tin <:. O.JY t Ll-\. • d -hi f="-'< f" fYl op m o. 1:--i OM
ori vOJY10-b\~~ ; vo.lut-~ .
P'::Jlfion dividLJ. 'tt,, opt"'o.-hn, i.D th, ~You..p~ L,k,
o.') --{\"<,tfime..-tic. ope.NCAtu'Yi C+, - , ~, I, ·J , *~ II) 1
fJ)
c.) b UJ ( ') ~ 'Y Q.,t L,L,''ff) (. tf) e.. bi f l ~ ~ V vY f 1('.) () 0 DQ I") L,L1Y) b €.JY ·
d) boo\(. ) ~ 'Ye..t: Uf'<n i ~e. b oo (e. OJ) voJu.e.. oIT fflt.. tp e.ci ~ e..d
D bJe.c. t .
~) c..omple:>1..C) 4 ye.. --h _,,L'Y r\ ~ r>._ c.,ornp l n. nu..mbe.J'(.
11
d, c.+L) ~ ,ye..-L.,wn( o.. d ic.. ti onOJYy .
~) {looJ-c..) ➔ "Y e.--tw,n, ~ o.. t loo-t,n~ point numbm .
h) ·, ntt) -➔ 'Ye..1:UJYnt Of) ,n+~9vY nu..rn6Uf .
n ! ~n l J -7 y-e.·tt,,uY() (: ~e. lUJ~tR ot o..n objt!,c.t
J) P"''1JtL) -~p'Yinh -m ~e. .do..ndaJYd bu.tpLl·t de.vie.~ .
~+0-fJdOJY d ubYOJY~ mo du. Iu :-
'Tl u. o.. w 11 ec.1:--i on on tmi pt- modu \ u o.c. c. e.).~o. bl~ +v
°' p~ifio0 p-'(o~rram -l-n timplifj ~e p'Yo~-YOJYlMin~
p-Y-o c. Q.¼ ; rye.mo,, i n 3 -fR e. n e. ~d -6 rv e.,w,y, -r-e. LO m mo n ½
w e.. d w rn rr, o..n ck .
2
II
\
0
4) Utr ~1..Lill-- -t:n r('it~o ck Ll.~td r i 1"-v 1n~ wrv, r_.10 Nl~O ( )
A) c_°'fitoJi e. c)
3 4 c.onvVYk ~e t -y d- ch01'1o cfe;y +o u..pfu({o.
cen+e-rvl) -➔ 'Y f +LL "l nt o.. C<! n+~f'{ "ol Ct"<ir):J
(Oll()1: ( ) --) ryQ --h ,l,rvnt ~e_ numbeJY 01 nrn et O "Pp( Ir' d
vo.Lue o l c Ll'Yt l/J o t-{"< ,n~
end~w1f-Rt ) ➔ 'Ye.-rwYnC. -t"' tJ.e.. i ~ tf), c.i -Ytn~ e.nci, t1-j1tfs
~l _c pe u t e. d v CAI u e •
+nd (.) ~ ~e..O)'<c.h ~ ~ e C.t-Y l ()~ ~'Y [). .c.r<2.Llveci VO lu" ~
ry L +wvY\~ if; e. po ~d:1 on .
1f\d e.,~ C.) ~ ,ye.-tUJYnt ~t. pot1t,of) o~ whe.M~ 1t vvOJ. iour·c
u.di~itl) ~ --h-t..u. it o.ll ch~octvr( tf) ~e.
'Y e.-1:UJYr'I~
~-try I n C:) d 1~ 1 h .
().N Q..
ur
th pV'< C ) ~ "< -t n -h tJ. e. 1G o..11 t hOJYo. c+VY .t lfl ffi t..
Q_ l,L/Y <:.
~~n+°'x ·-
l OJY\bdo. o..,,y~v..lY)ent!. ·. t~p"fe-tt\On
obj e_c.,h ·
i~nto.di w IL~, Io.rl)bdo. 'f-(\c.tionr DJY• ..,-u.hi de_i:J -W
on~ o. .tin9le. ~Yul...--i on.
J\ Iom bd o. r
c:li O() w.fl ./.o.k • OJ)~ r,t,L(V) bm t'l b =~ Ll/V)<
6); l,,J,,.ih °'botJ. l-- ~. UJn c.e.p l:- ot {wp ,_ o~ o. vOJYio.bl, tfl
1
rc.,t\0()•
0.
t,·Ju . ori~
;
LOU)
~1 rv-e..p e. at e...d ½1 .
wJ Ie...d
~e..o. d ( [ .( ic3e J) -t 'YQ.,0. d CA.t mo!. t- ~i~e b~tu ftorn f-ke. t Ie.
,y,_o.d Ll nt ffi. i;:,eJ) ➔ ,,,-,_a_ d on, e.1\-h ,,-, Lin, t°fY) #,, U' I, ·
-te.ll C) ~~rye.fLL'Yn~ ~Q_ tte~ U.VV'Y~. rit potihon.
vvl"'f Ite C ) -? l/0'Y I+ e. o. ii"'Yln~ -to ~~ i le .
frJ"<; h ti.nu (i e..9 u e.n ce) ...+ tA·wi h a. "'"4 u.mu o~ 1-h-i n9, -hi
-the. tie_.
d.ou.d- boo I indi u:>.-h113 +g, w1rre..nt t+o.-t, o!- tf;,_
~bJQ_ci--
f n c C' ~; f\ ~ - tt, r e '""r r, rl ," 1 r~ r:\ 1 Ikl ~ 1rl , ti I
ct
~()r,t,e I'
C1"t1n9 t~r.l
1",v, ' 1 ,,.,
tf\c~1lO ~. \, ' ' "I ' ((ll/y(f r,t0
tt, t
1,I t o I~ () ( t
V\,o odd~
Lk. ov-.lj l
d i ~ !,'Y rn ,:, w. ttu V\0-JIV\' 1t\ocr LI. 6 0 u. () cl
iM Fa,-\- ,'f b, ndt ~ nOJY1 e '':J' -f,, ~, rnodu le
wh; le. -f,,-om -'::Jt i Ml po'Y +- OJ'<~ v b, nd t C\ d It\'-" e.,r,f-
n O.(Y) e , OJ¥') v , po , n -1-i n ~ r h "'"i\t °'+ -tR e ot ht buh
!,Df)t" 0-1f")e.d ,n~1de. ot ~~ r-l'lodu.le...
-
-[rt-.:~
--l:-rv1j :
p'Yintc~)
e ~c. e.r+:
P"< 1n+ L\) Of'i e.,"11..c. e.f o(') o l c u.1'<')' o_ cl
1
')
.f '1- : -
_,;.-
,i ') :r p ,n t CJ.. )
}. t Cr~
f"' 1n l (" ~, ,w Wu 11 ' ) h '! () I c, , u,~ )
f1f\t\ lllJ
p~ in l (' ]t'0td 11
)
fl) f'i<(n ~- 1'1~t,' t'> d ll ttt, d cdw) cl, 6.,~1 '"') ti;._, c.od, .
.'.f{ Id, ~l'L\ -l«t it C\ conclihof) Lt) ~ou-r cod~ ..,.,/wvn
.,-;Ll ~ 1 tt r'it:+, 1t,t p,o~,-a.m will 'Y~1~e. 0..'1 -A< <.Q.YHo()tn
-['\ •-
-=-
<"'I,_ :. <' L, Cl l t' ,,
11
O...l..\.t.1t --x. =-= ' JN·db~e. 1 '' /\ d "<-CLLld bt ' kello ' ".
Lo_l:'- -0 O...lAJ, ~~
0-) op('f)t)
11:,_ Drtn() irf)(. t, Or) 0 p €.f')( (),_ ~ tt_ 1 ,S 'Y'QtlLYn! /t- llt
o.. tte obje.cJ ·
f~f'ltO..>C
oplf) (_ f I'- , rn od e. )
i1!t - f°'-~ ; no.me ocr rh'- t lt
rnod e - '\" 1 a, w, 'Yt(f'l e-~d, o..ppe n d 1 tv'Yi l-e 1.'Y ~a.J ~ Lv"l ite)
t) Sttkl)
T'
- 1 u.
l-l-1.e cl -6 th°'Q' ilu po(ltlo() ot ttu b'•
lo o. JIVQfl ~Fec,fc pot.◄ hm.
i~f\1 Cl'(
-f ·i e~ k( D[tu +, r,c rv,_ w kt)
olft(et -~ 11\.D· ~ pouticvu. -to 1/\ADVe r"'~W d
~rn- wk+ ~ po1rit oi 'Yt-lVYttA..c.e.
d J -t Ltl (. )
-le l I ( ) V\A Qtko d -YQiUJYvu. tlv. UVY'Ye V\.t- tI e. pott h OV\.
~00+0-x
+ fe
lt_ • 11 C )
e) --n.o d ()
J-t:- y,1.:tLA,'<VU. ~ ~f e.u be.d vW ob 6~f-u awl/\A ~
Vl i . Dito..ul+ u. -, wkJJA 'Vw.d,<- wk.oil. f I~ .
~jrit0-.)l
1i'I e rytD-i:i c )
·i\~e. t-!:. o hol/lO-,I,
1
~ -Hov.:, Jov. -+~,'j- vic.e-pr d:-oJul' -e.rt 1 1 wrrtf' 1!)emo\AJ..i.Yo.1.t
1
tlu Q})\.c_ r pt 6 Loe k l~h LJOIA ~o.. tNJ /e ikt erv 'YO'Y.
(V'\Q.¼,Q.. '
...[')._ '.-
-lJ.
pv-1n+c~)
e./XL e.. p+ :
/ \nt ( ,J 0)(c_ ~y,hO () v )
__g t\l\.C. e... ~ -{ ,y-~ b Loc..k ~oJ ~ u D»\ VY'YO"{ J tk V>lc..e.pr bLoc..,k
w1' [ \ be... (U)Ce.ud-e_d , t,.J ItRouJ ---t<y~ bLoLk J tfu pyorOIY)
w 1[\ ur o..MA .; 'YO..t t e.. Dffi vvrr ory ,
'"I(\ j'' d n 1ti"{ ( /,\ I \\l> I( L "11 C >-up hem I ft:,IA ,+ •rl
n ct" C i(" u,dc 1,,~ it I,,,, ,,,\rl u, c >.ce p1 clau.,<,e ·
S:tL" ':.
O.<C r/ (:[>.Ur lion I, [.,., "-p+ioru , ·.. . [ ;,.u,,b o() ()) 0..,, e·
{i:-
lt"Y-TL't t (. ~ (
-h:f
d _e
d d-r 's '
I
I
II
I r/\_r k.t-"
I tt;_.. t
cl• f'" e,. ._cepf AALl.!,c "" tku. w4 , w • etx.L'ff-
-At~o, we...
QV\Af
wd • -b -/f;'Ytl\Al di ftex•IA~
e.occ.ephow. ·
WOvV\. t -Lo -l o.. k e fiv.. a.c. -H tJn i..r, e__a c..k u:u. e. •
.r) lrJ W o.x. w V\AVv\ o..w:J Ge, j
o.,y LUY\ ,,,J:;, i, '-"-F' Irun ; f-
w i tt\ Cl.IA '"~•.
i,I,_, t'.O V\A VIA o..w! li.,,' 1 w VIA pl • h IA'.l i JR w 1/\A,1/\AruALI Li.uc e
t optiov\. ~ Lou/\ b t
D-, V 1 t,UY1 Q.. V\ l.
JZ.
"J
pcwt e__J .
/
Rji:R-on ~ :f mo du.,l ~
j l irr,f l '""" , "'-{c w IMWI ou,,v:l - l_;._n , OK~ u.m ~ ""t, t1) 0 ~ j,.,,, pI,
Ll t t ~.A "(1_,L e..1. u...()'""~ !/\CUAA e..ol t ~i . OJYd V .
iV\A--porr+ t~i
pry10t-(1:~F- t \:~i · ~v))
p-v-; IA t- l" [k,. COWw'\A~ b..o. O.f'f<r W, wclA Q,Vft '. " )
p-vi<Y~ Ci)
rlev,o r--lopl: rV\odul,
Ii J-! m.{ wnlt tbu_ s•p=oJ1otA o\ \k !tA-pu.+ thi"'Q ~
p o-r-r()J/\A ,J ivr vo.. Li doJi o n .
-r~ '.-
i'~o/\ft eJnp t-
0
t1AAf orv +- ~~~
~v ~ c~1 . owu0 c :J 1
rf or,f
opb., Mr C ''rfup+. ~~.\upt-(M~V, 'kw,J ~
- -
p-Ytv\t LO pb.)
P"" i' () 1 l l'. v ~ <: )
e'>lc.e pt- Udo pt. 9et-opt{-r-ro'Y.
y, i'n+l ,, iol"l\df,,; n3 "'e()t "'-l'YO()~ ")
~,Ji. ~)\_it(:i.)
b) -f"f ICW) i"'f u+ ~ ou.-f pu.+ V\,v. ftod ( o ~ o. t {L
'1J -I) f I, 0
pt ,o.-1-iori -fo.k,_, pl0-u i.n ~< pu.owivj odvv .
a) opon o. t' le
b) ,y Q o.d 0"( W 'r I h,
q_l)P-lAi 1
°' wJ Q
It--' o-,- °'fP".,J, "' -lo tt,.,_ l' I, 1,.J, = a..l.w '/'w U'o i!
we. t-0~tA--t to o pe.tA tk.t t lt iY) -le.:1t.4 1/\A.Ode ~1y 6 1<AO-.Jv~
V\,\.Od L.
t,L,v l
W'YI o { ') W " I~ o rl
f lAIY"-vvu 1,.M i.. 1A-Oi 'J" «' t"~, 1I ,yo od L ~ ", Ii " IA' , , I fo