Partial preview of the text
Download Python Basics-Complete Handwritten Notes with Examples and more Study notes Programming Languages in PDF only on Docsity!
* | | Python Programming with et 4hon —,— Python is a general a pose it terorete. J. 1 it = SA yraneetntig iatetcges nied ana high leve| programming language -_ _ Applications in areas Irke - | - Doskton Boos _| : - Web Apps | I - Nota Mining a . - Machine Learning | | “| Python is alsa known os multias pose ofeiraminy, language. é i : — : = “Ii Pythan 1s created bu Fuiag Wen fessure pouting I9g5-1990- _ 4 x] Pagtures | : 7 1 ; : [Python is interpreted - JP is ororassed at rinttme bu ‘a _intorpre ter You da not need tn -nenpife |_Pragrarm beforo _aversting i+. This is sim! | +0 perl & pho- ~ Python is. interactive - tl 5 it it ato outhan oramntt i ou i ac at pene. —and_interact wit the inverore ter dirertu by ot tribe Your programs - i — + Python is object oriented- = Python supports object -oriented style. -— or technique of programming that encapsulates cede within. dbjecls. _+/Plalform__Independent- —— = Python works on diffrent platforms (windows Mac Linux. Rasbber ny Pi, etc) __/ Tk supporls fianchional ond structuyad_pragra- MATa. methads as. well as gop. ltt canbe used gq 8 a5 coriolt language jer can be_ campiled +o byle ~ code” fer — building lorge applications. | Tk__supporls__aulamatie _garba ge collection . “11k can be easily integrated wit Cl cee icaMl AcHvex , coRBA ~ A Tava, ; | = ‘| Python's syntax & dynamic} yping with its inte roraiad! — maliire « tagke iMeriae 4daal’ language _tor _stripting and rapid _applica~ ton _develapment. - _ 7 —¥Hike Phglhan tbe = IDLE >In jeqraled__Development _gnd_Learning_ | Environment. -Js a default editlor comes with Pytre —_|.- otherg are - like | spyder, jupi key | Pyctharin, Pydev, Sublime Text3 ,Atam _ Four diffrent Uy pes - yak en aes types ~ N Floot = —_— aes a = (234, j__ivi_campley sc. -. 4-93 — ai string — Specify range _using _range symbol (+) st Ex a or fowernment Karad — prinr (styA Co siol) 7 —SiP -_ last index Ye Government _does_not induding — - aw = _that index Ex: orint (stra [1 94 Steep _ oP % Covernmen _ EY: arin (str4 t ott) _ O/PS Astaveadse erste 2a ate a Karad RE Ex: print (stra fJ)_ - ad OsP Ss Covernment kovad fx. _orint (s tr4 {o 1-23) a we _ oP > Government kar 19 is starting — ond -| is ending —_chavatey _ | ; —£/4 js concatenakon operator "ik is yvepotitigion operator itasterisk) | _—tlemate | (me c | “ ars fastorisk\_ i Kotte | pete Ex. sht="karad” print Ost k3) - -— a; PB. eet ePue i ts to / kavadkorod & feamd-wologi iy tet * Gxample et Wish = “Wella. Woeld” “goes eo see ys _orink Cstr) # Hello “World _ _ print (sty fo) _# OH. a re potion tt Mee ot Oe Oe | (sty fo:7) #\lo_ warld _ sink tsir *2) 4+ Hello world Hello world _ pyri mr (sty + NTEST! ) Hello world TEST ra Lict -Compeund data fe? tye ins 2 -\isls contains items seperated by () and enclosed within (Cr __|__=Helerageneous data ype | cx: | isti.= £1,9,9.4F) | print Cisti a = | O/P> Cl, 2,3, 4 | fe: Ishi = [1,2,3,4) print Cistt + £5,6,73) os P > Be U1,253,4,5,6,7] */ Diffrendate belween list & tuple Rn fe eye we print tupletod) Pee BE Ever» rae eS | | print( duplervesdy) | print’ tuple a2) er eee =| iprink C tuples €1)2.3)) f | ¥ Diclionony . a dice {ota Si"gpk" 5 743-5, "a™ s Nabple® } _- Mutable _ * F x i> Dictionary is a_collectian of key value __ipalrs _ eeferated by comma 4 enclosed within ——icuvly brackets (44) . : eo = Nat indexed therefore __connot use range operator ©) = ___| = keys con be used as index | ‘ | dick={ ‘nome: john’, code’: 6734 ‘dept’ sales} I | print dict F ‘nome'd) i # john print (dich. keys (1) H-ovint _a\\ keys __prink (dict + values 0) 7 print al\ valuep— fx] dict=hy_ foo ; dict Cloned = "This is ane’ — | dick fad ="This “is no! ay ‘&_Identation. |? Sdentah'on is_nothing uk sparergiven lot the begining of line ~ to deRine srope E— seal __|eode.— a Z cad ae | a me \| | Colon) 5 —indeniation on. ~symbal - ica wa a= a oe | = re 7 pes iFlazp): a —— -prink Co is large”) else, I —— print. Cb is 1 large") - prinkC' End of progiam") : = ae | “ysitos Sython— Q _Nnito: Python Operators _& Control Flaw —stakments a :| ke, Amportont —Funclons _ _— =a Iprink Q= sogun oe a! 7 | Syphax print Lvelt val eval ender nee Sep="_", ond¥=“\n' ane ™ seperate x Sie Hello", “world”, | sepe" §-", ond ="%" “al Shaul OQ. an 3 — “Syntax = : = tt —sty__inpur | str) 2 — a eee = || nomes input Fniey your Name Ea oe |} es pint (Hello name) _ One's cornplernent represents negative _hunbers” Th pees oe Cke sl CaM 4 C/E fect tthe 4) logical Operator _ _ and, ar not an ee ee G0=Tmue _ —bb= false ow —puint(aa_and bb) > False i 2. Bitwise. ~ Opera bors 7 a \ he Sere ac ras a” —- Wen eYnany One's Cornplement — {he Be _6) Membership Operator - _t in = Evaluates to ine if it finds o variable in ee ee eeueeiied sequence b false otherwise | inal in > Evaluate to te \E it does not finds a variable. aan sequence & false _ otherwise . i —E- £2.3,49,1, 5] —- 45 in list pie | _ ae ofp true _ — _— ts invdiet so sents L op Folse . 2) identity i) is > Evaluoter Operator (>) 2te___waF ————. ~ a ar, ty Ime ifthe variables on a ailhar side of the operator point Jo. the { Same object. and Folse otherwise “il is not > Evaluates to Hare fal \se_if the variables | | of + the_operodor paint to on either side _ — Same oblect & Ane other wise Fu. o:l0, be20, cz10 _| — ois b > False |! —___O— — ois ¢ is nok b => tne => ime i} —& fontrol Flow is mot c => False 1. Conditional Statements (9. Loopi _ 3: loop Mmanipulatian nls. —1_fonditiona| —siatements > - ; i) if _stmr - : __if_ expression: {3 statement Ti Ex. nume int Gnpuk ¢ “Enter Noi) oe ee a ae ae oe print (Number is even") 4 \ Cc = O largest at SNe: b= int Cinput_[ C= int lnpul & if arbi SNR» Be oe on | else else? — y a» —— } | a aE be: 7 __printt®b is largest") Se rter No-13") 7 “Enter No-ai") er Entey No-3:") are ceed orint (“ais / laigest We ptint(* ¢ is largest") - inh c_is_langest') wihkthey arcepked Nov RA WW: Python prg__to check Pasitive or negative Aveta int Cinpud (‘Enter any Now if no==0: print (“No- is Zero") = __#tee else: if novo: print(*No- is positive") i else! _ print (*No. ts Negative") _ _% Looping stalements - : i) while loa p : _ om” i While expression: - | Slatements (3) ) Ex. ee Count: 6 ee : = whilelrounkeg)) : | prink “the count is, count) ! counk= count +4 | print (Good By e") = || = == i) fo Loop ihe 28, } S yniax co tt | for _\levating vay _insequeme + —___ | shalernents (s) — AiRange 0) Funclien- : | Range O functions reluins a sequente of Numbey sorting Srom 0 (by defoult) , and increments by Thy. default) “and__ends at specified Number. syntax - yrs vongelslask—end ,trerement} [| print( range; ny) 4 prints 4 to 40 print Cronge C¥) 3 — | print Crange (2.2) 424 € & 10 | - | | Syniox ‘rn —vange Cinital-value, end value, increment) en — {iprint 10 to} =, — . ? 2 - 4 Loop Control stalamenlo= 0 Loop control. aa | a \ ments _ Lit sohano ir 7 fom —its__narmal —2xetution. ng-e_executig a i break eee : (2. continue | aah 7 I oa AS: poss) oii, ite: eleesha _ 4. break __Stalements _—L = @—the current loop & resumes _oxerution ——o1_ next statement. in a. continue statement — = Returns control 45 hegin'ing of the loon = Conknue _stolements rejeds all the remaining stolements in current eration a hoop & Moves the control bark to the top of loop - __3:'pass statement - ae is_used when a statement is required 7 Synlactically but vou do not want ayy comma nd ar code to execute _ IE pans simt is null _aperation ———.-nolhing happens when it execute. _=Tor loops cannot be _emphy tout iF you for 2 booms reason have a for loop with’ ne — |_conlent Put jn the par stilement toa avole! getting an etror a _ foxr_v info,12): pass classmate. be Ce ey | (fe a 4. else slolement . — =! ihe in i. = 7 - NY = _ IE Pothon supports To have else | associated with loop stm. me else sim} is used with far loop, the aie sholement is execuled when loop has | —S#housekel_—erating — ee . _-iF else ctmt ust e oop the else —_estakement is exe Talee. | Ex: whe | for i in_range (1.4): une ornttd \ | else: { £2 3 Ne Bred | | print ("No Break”) _ Px: for i in range [1.u): +E print) | if isa: \ | — break Jia | else: print ("No breale’”) | hime number aul alse x: | tint Linpur ("Enter No:*) ) | se || forgéele in ra ngel 2 Tw: mi as L_ iF T to ele==0: a pena print(L, “mot prime") 4 | : break BI I else’ : ee | print(* Pe Tr Primoe Number") A _ ok. Acessing. values in are -_ “elUpdeling a isk i _y Op pond) method _ - _ _ Selon = ish obj coppand (objec A siz £),9,3_ “Wolo | [tate append (4) a es ae ere 12,3 "ello at = “extend method ; 7 ‘ rn = Synia x= ust ob mM oxtond (co lection) a haa ese ACs! J —siattond (182) TUA A BVI. BH) _tst extend (114,2,8-83) _ 3 fea ne od ak : “Syntox = —liskobj insert [index 5—e bs) st: Corsa) Lysis [2.83 Meul3 A re 4 —UsteinsertC2,'New') ji : 4 ce —- = emt | I ROT ST — # Deleting list olementa-daael fal clu lad 2 : or | syntox= del la} name _Lindexy ae ges — en eee - — — S| Ist=f,2.'Hi', gg) _ ee — ea delflg4rat* _ ~ _ | de}ta-—}s— _ ste del isa ; t Delete entire st __# | Remove 0 method _ | Searches for given element in list & reMovwes /Siast cnatching element | Syntax = list. remove loh}) iste 01,2,3,"Hi', 3-50 J 1s-remore(¢) _ Ist. remove (2 Hi") / error it is net # icloar () method _ et rie t This. method oemptice the list Suntax = list clear () ; | let ef 1.2135 Ist- clear 0) HU print(%s) > C3 ellen method = = = Find out length of ligt EN | syntax: Hetobj—ter £5 of Len Usstob}) —__| Eg-ten(ist) ae.