Docsity

Python Programming Lecture hand written notes, Lecture notes of Computer Programming

Partial preview of the text

Download Python Programming Lecture hand written notes and more Lecture notes Computer Programming in PDF only on Docsity!

Page No A E ae [TFT | O57 = nid — x | Pith, Aialamendelan + © feature of Pyshon , Python ‘imleprelen € __steuctaye of python _pkaztammi @) Nariables_, operatovs, Data type, £ Tilo slotement-_ ee @) Conttoad i steuctter 3 Decision & loops. sting €_sternt Operation © set” Dichenary "st € Juple, © fanchonxs & Regumouts. Featarex of python go> = simole € easy to learn = syntax is Sirmlaw -to _eng\ish . z_ interpreted danyaage —s execnter Code Yine - by dine. [a > pynomically Typed —» No need to declare 4 dota - ty pes. a > plaifesm independent —s weidte once | tug any tdherce L 7 \awqe standatd liza 3 | oa 7 Open sousce — Cron’ “s_uge € modify . 4 2_object oviemied — supporis classes | objecks - , ae > Potable i : ww) Python _inies ptedlen »—> s >_Ppudhon fs an ‘intes preted an gua ge developed by Cewido jog § Rossum 30 | the geac IMAI | Date t Page No. ——————S SSS SSE SSS SS > he modes: language = Puthon Davascrips = | PHE . ee e 7 Corn piled fanguages =O, Gxt, CHE. 3 7 wiencprerteres arse ane ceomputent _pageay> Anat wi Copverd the sousce code ov an high level slanguoge info ____/ machine evel Jan ngu.a ge. ft ig abyn Called -~teanslatoe \ Sousce ‘milerspielers | e xecuta)s \ cade (ee Code ; igh Level Peeg a Cmachine Jan preg) T Janguage. 7{ i ; i out puck , b 7: : : btw mie heaps a | | E | + [eget wert: : Snsteuchon Trvtek pCO wseking Steuctige of puihon p%og Eamming “9 i’ QQ peint C wells World pr) O/P=s Welle Wwoetd ! @ name = pkacht ! QO =. -\0 —apint C name ja) ofp eee PEacht \6 j Page No. — ae I —= SS 2) Be declare Nonfable 83 a OQ =20 azo oP 16 7 pemt Ca) © Assigning _Nlaluex to multiple Naviahle t-3 7 Qe b=cC = 0 q S/P3 16 10 I ptint Ca, bic) ©} pssigning —_aipferent values Jo. _malile Lada hes - ‘ Qvb.G¢o= lo, oF, Noy I printf > Ca. hiocy ‘ | 0/ P= 10 QF mY 2 (® aS 18 Of/Py bry 9-50 be Sey 2! class — ont ptint (typec ax clas = Float print (supe Cb \) claws~ Sie pefat (ty peCed) Ore rien VT ae eal} Page No. a ‘Tthene “awe. 9614 ty per - vaf Yoria bles? Abba “vonsable_ fy: ! Lig ntantahle: Aéolnged Leudaide of juthe Fanchan Oo Scape of variabie La global is cated global Nawiable: — A___jloha) Nawiabie is algo use _ nutside ot inside of she Fanchen: £4. at=_“glohal! 0} P= def hello cy 2 p¥inf. Co 3 global ello cd Wanty 89 global print (aircan) Loca) Naartahl e 83 2 A___Narwiahie declawed _Sngide of the Funchon 4&8 Sa Called toeal Nasiahble. 2 Local variahle cannoli use outside of ashe fanchoan. &a. ___def hello > ¢ OPS inside w= * Loca} | > local print C2) ZRVVOT hello cd | ping Ce budside. 27 Elogt s— aOat > This volue 4a wvepresented by the Sloat clay. > AN ig’ & seal no. with a floating -point sgersesentatian . 37 Complex Numbey fc __complex number is represented by & cermelex class. > \t is specifred aX Cexenl past) + C imaginary past) et 2% et Q Aum >= 5 numa = 2:5 numa >= 274) print C-type (num)) peint C-type Cnum1)) print C type (nume)) a So ae fps clasa ~~ int | class - ‘float ' clay ~ “Complex * (2>| ceauence dotatupe An python &- BA 4s she ondeded Collectan of Siomilas ere aif Feccent pubhon data tyoes. 6 —1t__| [Date] ee ee Lease 7 | @ goto, Be ty tt Ea xt 7 q—t- - a ae esis Yay ‘ss whist can he created using ngle quotes, double Auoter, ax« even eres “quote 2 de can access “ indiuidual chavactens ok, a string Sin ‘ : ra Lai a index. Sa S= * Welcame ts Adarsh _c)q! ° ce) peint (Ss) print CtypeC sy). peint Cat) io ae ed weind Corey 9? | ae? MESS print C sf -11) _e/ps clCome ts | Adatsh cla Clagy - ‘ote! ae C's guia My re | | "5 (D_ lst z- wa es iets ave just Vike adways Lased in _othen Janguayes _tahich ta an | atdened ca\lechan o4 data. _—_—F : zi\b fs vyety fleaible a3 the jemi / yo bay in fa Hist! + ‘la mad need -to be of —7 the Sam © type, ; F = —— : ot a ‘ ef _ *& delede element ‘in given ist we as [\ppple! ,\ banana’, 'chearvy/ ) _ ae: 2 -Ael atid _ . _ | pttind Ca). = | ops L_‘pppl el chery" 2) J @® Tuple §- juple _ 2 Vust Vike a list» a tuple rs _ also an ovdened collection et es euthon obfechs- The only aree hetween a tuple & list js that, tuples are immutable - > reans 'Tueler,canno} be modi fed after i {sa cweated. Nels -Tuples can also be cefeated with a Singie element but 5+ fa a bit -feicky. _Haning one element in the Paventhese, “4s not suffrcient thenxe must be a sealing ‘comma’ to make It a pt teple. a = € sxy2! 10 , 2:5) b= ( to a ' print ( type (by) o/P clay- tuple’. —— + cces\ tuple elemen ae — | | , oe We Can use |} tuple! Keyword tt |__| Acceyr sh e tuple elemeut in |_ —__ indexing - — Sy. A= 4duple Chto htc!) ) punt Co Tol) Print (of-\1) —_ O/P= Q = ia = Boolean Data type s~ In P®ythan , the Boslean daia type fa used +n te present teuth valucs- Tal ene Tene ct False. _ptina Ctype (oD | e oe Q= Tene ei b= False ptint Ctupe Cay) Zz CIPS claga_- * boot! LL z 2704 =S oTPs | Y= 3 Teue iz Print ( >) fals € pent (x= =) clay - boos! —_ a he S {Date | ee Page No. | ee: a Pra Ci. ee, Be BN ; | 69.2 T3454 _ pert 7 Sl union C52) print C 5 1-intetsection (S29) print ( al Mer edence C52) }—_— Wire Yt dBi, oN ; | Lat q | 1, By * | Add 5 Add nerwd clement +0 the set deyrnt > Remove, a specie elemerdt- clean = Remove atl elements +c sel. eS. fiusts = f‘apple' ‘banana! t fewits- add c\ otange 1 5 L feuds - vermove C\ banana! ) print ( feuits > = feuits. clears cd 4 ptint C feutts) s/P > 4 ‘apple’ ‘ ovsa.nge! sei C+ (5), nictonawy 0910 ype £2 © vali 16! fas > _pickonany hold rer! a ae | aie. > each key value pare in o_dichonagy = fo gepanoted by a Colon 2. = Lane e as each \gey _fs_ separated by = | a Lecamma! “sitll The nbadaningeye covy also be Created | ! wy Ane bud ‘in dunchion dict. © Lwoltis dichonawy keys are Case -Sensitive | ey. Az iisoy2’ 4 a2itabc’ , 3: ‘ part} AL = Met C4 rr torye2' yg 2: ‘abe’ F) print C-type cd) S print Ctype(aly) o/p = aicst | sen age bat * Accessing Key nalue in Dictonavy % ge VAT ote. arse! ¥ print ( d f%9*) PEini (d- set C3) ) off> ita) Cc (we access _pichonany ‘dem\ uring key name __ct get function J ee | Too Bittdise Pensa to + Types of _opecattors f sam Lay} LY? AeAhe math’ col ne 2 Relational openatnx _(<.<2s% | | i t t t 1 *, 12 - a eee e Nea? enatarc __( AND, eR rs C €,\, 6612? A) a ewan Ass: nro et openatow CS s5y-s*s ) F e ener | GO) Rerthmetic operators 6-3 - sh 4c used to Perform baste Marthemakcal operations \Wke addition, | & = { Suh, mul, diy, floor division (teu) yines “in Floor), modedug C i tives | femaindes) Power .€ ea. = _o= Snt (input (enter Bast no.” ) ) | >= fnt (input CY enters second na)) c= atb A= a-b © = arb - Fei a/b i A= a/b # Imeqer division. a he a%h i. { = areh H_exponentkation apestiet— pent addition fo: c¢) = | pert (" sub iss" d ~ | peint C" mul isi") e) ~ | ptint CO" ty ins FY ~ | print CVinteger atts 2g F = = — — _ —— yO es ~_( eeevatlae 4 As a nd Cs #8 expo ne ntica” at 1S. ri) | o= 4 Ste | a thea at oer thon ‘a == : S9Uua) +o are 2 2= J—_ XE =} | ca hot equalto aay | > pagidtnicad than ura ersy | equal to t~ mS Vex Ahern cr ex = y | equal +o r | ee ie fe ce ene ee | = ) Page No, cor Retarnd ree fd ether, Ore 1. toms 1) Reducns Hue oF the 7 $Pesand As false. Qa ee) not 9. LA —ttedh Aable os nk Yi) monde os H and Y Mer Y | nos oi I + = a ‘e To} et E ‘f T —_= Cc i. Cc + | a. O,b C= Tene, Fatae . Ttue i¢ O and c? SEint (" Both a € C ase diye") it ob os C5 ___ptint ( “ether bos © tse) Aj not _b ¢ eeint (“ Lis False") O/Pps Both a ¢ c ave “TRUE eithers b or C55 tee, bb is falae, Date Page No. Ol iiss npenmadses 2-2 — > Sh tet 5, wack ao_parioen ———__| caleulathons on inieyexS — PF the Anteqexs ar xe fons —Gonstexted ~ into —_bingry & then aire ane pessfoxrmed on each Corresponding Paix of brs . | decimal fxxema t- > the yesalt “Fs then oCtumed in Nate §= Python — krhoise -apetotaeS Work onty on “integers. ©) Biidise AND 2~— * Convent Sintegenc no» Sato binaxy Soom € perform ‘&' openatan. 4. a A= \6 b= 4 . punt (“Sa€h=" aeh) Psa 4 €b>= O a bina" 2 go! 2 \o = LolH BY 24 4 > € ono Qo 84 (6) lo — - 1