Docsity

Python Programming Handwritten Notes – Complete Study Notes, Basics, Syntax, Concepts & Ex, Study notes of Computer science

Partial preview of the text

Download Python Programming Handwritten Notes – Complete Study Notes, Basics, Syntax, Concepts & Ex and more Study notes Computer science in PDF only on Docsity!

Da 7 ~~ PL j= Date oo... = PyTHON. PROGRAMMING ;>- Inbsto ducing Puthon - U res — ~~ —> Puthon t& a Wigh- level, geoual = puripose and vewy. 0 opular pro ogrammitng Janquaqe. _ ar ts bea used ™ Cue development , Machtne learn- © ‘ia - “4 apple tous, ete. —— ye Parl on _Pxogvams one qenematly —smalley than the othey_ puogrammamna dong ua Gs * __ Programmers CO have Bhs Y tupe Helatively less and the ° 6 wi a adentalion requirement of the Jang'uahs p makes Men Jj ~~ Headable at the time. a, | > Wey Simple Suntax. 3B Easy fo leatn., d f J uv ~y i buint (“Hello”) = % an General purpose dnngiinas 1 { Simp le et seg powerful - “~ , \ language) - : “> Console Application R Scripts - md L—> Desktop Applfcatfon r a E> Web Appltcatfon ; = Pa [> Game Development - La A 6 . Bk Ly Machine | learning °; Beep learning , AL , Bf data ek- a) U ' i) u = Ca Muttinaradign Support ir |” Puocedural Style Programming like: C- ~ be O0Ps ike Trails y Ae oa i> Functional programming \ike (ist. U vi sabes — Portable or Platform Independent q 0 ° ? an t = Puograms are typically first compiled nto f 4 fnlermedtale. code, then the ‘ode fs yun by | {-— he inkerp elen $ 4 - ¥ —>_ Ddynamreally Typed J N SY ot = 10 4 yz “geeks 4 vee Ue python” ; This feature & different fiom C++ b Tava.) They 5 ane slatfialty Typed F a " v g \n suitien: ise don'k have to Speetty Met, vantable name. Bul the disadvantage Gtn thts the type & assfoned ii ° o VU vt m the yun tme of the g paogram , so Mere are 9 | me move chances of yun ime error. } = _ Automate Garbage Collectton \t means when aa dynamreally allocate memory So you don't have. fy tabi yy to realising this memory y q § => Popular Application Built in Puthon i x Youtube i Neteifx:, Duora Instagram . a v Drop Box 4 4 =r byint () th Python — 4 A functforn. & a set of Instructons: Hhot take a Some input from ua, do. some Work on those ‘ 4 <9 eet => _Vautables Pn Python = : RIT Nawtable t& a name that ie ated to siefes to memory Jocation. Python vanfable & also Known at an tdenki* -frey and used to hold value. } a — is \n Python, we don't need fos eciPy the Hype of = total - psitce =_fositce + bax i) paint ( total- pufce) v 1 Voutable because Python boa tn few language and S 7 Smant enough bo qet_ _vantable type.’ iy s) d df — } Example - pstee = 100 b tax = (8 Output - 12 How vaxtables wonk 9 “= 10 Uoe]=—* ie geet é geeks ail 2s ao 20,2 ee et | ad an Mai] ath low ami ty la | as aK er! Ob elo | then 20 [Sos So x but tf ; “Wt 80 Bo ew y pe O]p- 0 n : 8 4) geeks paint (2) ee pint (w) o u 30 NOTE - Using a vaxttable without assigning fk cause evror. ———> U g g “wr Ee psifat (x) ~~ o)P-__Name Exvor + name ‘x! fs not _asstgned + Ug ~J = input O) in Python - This function "used fo take input from the user ; t Example - name = input (“Enter the name =") | paint {* Welcome’! + name) O) Peo Enter the name = Himant Weleome Htmanf Example — # Python program tor addition : to 1 a input (“Enter First Number 2") 4 = input ("Enter Second Number : ") Tat (%) = faite) w plo] well me law lel a wn“ u ys ~ ems: Ss one a7 ny (1 ae. + 8: Sp sett) eta, AP modify c once you created. , a A Inese are cfomutable) aman 30} { Set & a collecton of thems $= f 10) Ses \ 5 ot where all thems are disttact int ( type (s)) 2 PSN GY 2 aTal {hype 0 and set U dike mathematical Set) > d 160" fg" 90. “ide"y dictPonaries are used to do _ : . 1 J - : } s. thy 4 ia SS int ( type (d)) mapping 3 , a eobleeton of a value patrs) tq- Tkems ts: pyices , yollnos Name. Tt T ws = 2 axe Tupe conversion Python - a ye i 2 3 Impltett Expltett a alo €q- 42135" vers J 14 Jak(s) > aa f = float (4) ° o 5 i= True putot (3) se ezatd pyint () , paint (e) » opp tyes o}P - 14S y it : 135-0 Ege ciz dvs: * seule a a paint (dist (4)) bi paint (tuple (8)) & _parok ( set (4)) e Date «...2..660... = Eg-3 a= 20 — - | 4 if paint ( biofa)y _ Pa _paln} (hex (ay) — : — one +t paink (okay) ea ie, a : ze ee ae ee Ht OJP ~ Obto100 ae ——-~ He Oxy . He 0094 4 4 —— t i “=> Comments in Python ~ — | We may wh to desenvbe the code we develop . We § 1 e ep V f why 4_ section of Sul pt | might wish ~ ty take notes of r pir veo _ H for fnstance. Formulas , palocedures ,and fophtst? caled — | business Jogfes are ty ypfcalty explained with comments | # u r Single ~Jine tomment - # : " Mult? - line comment - # oor # wt a boc-string - The string enclosed ty Ftp le guol-es _£ that conven immedfately after the detined pn ane catled Python Docstena. & ) U re SS iJ ° ° = and elif in Python — ; ip else and uthon 6 Sheve come sttuahfous Pn Heal Jife when we need to # do some Specific task and based on some Speci fie Eo conditfons and, we decide what should we do nek. . Simtlarly Mee comer a Situatfon %y PAoqramm in: s whee SpeciPfe task do be pe formed ip a. cvecll 4 Conditon u — true. % Seerat tee. =Use statement = In conditfonal if) Statement the additional block of code ts merged _ at lee istatement - which perform.|* when se tonditfon “tu _ fatse - ses _{tondPlion) s G3 i H: Executes thts block ff __# condilfon & true oan _ else! __& q # Execukes thts block if wf 3 # wondiltton & false 5 4 8 Flowchant - { § 5: paint ("Biggey than S") if num 2= 18: paint (“Between 5 and (S") Biqaey than § Ud Between 5 and 1S te | yy a ih - elt? Statement - shortcut of it eelse chan, While using tf -eltf statement at the end else block uy added which —u& performed if none of the above if - elf ctatement true. piel y ~~: Date .i.sscccccees oe \In python. + | the addition operator. tt Ad wed to_add 3 valuet Ease’ ~~ Example - Noll: ee val2 2 3 coe Hes > val it val 2 > [ane _patat (att) oP - © a Se SG Subtraction Opevator_ - used fo subtract the second value from the first value. 3 | LY Example -_ Vall = $8 5 vol g = 2 jae 18 ae dea = val - val 2 ~~ print ( 4s) 5 : . @ Modulus Opetator - Jo asthe modulus) puro uted to find > the remainder when first operand u divided by the ~S) setond 2! poner mesic = Example - valt=3 val? = 2 ~) Hes = val\ %o vol 2 >. putat | Hes) >} o}P - 1 A) Exponentiation Operator - %* & used fo raise the trsh y operand to power of second, = Example - valle 2 val2= 3 a. > yes = Vall ** vab2 Pa print (ves) a i fe. re | 8) Floor dfyiston: - // 16 Used to fad ne floor ofa: Dae duet h when first optyand ts divided by. the sttogds i Example - voll = 3% BP ORE TS ORT aT : voald = 2 ee ae met bia Ee, Mes = val I // val Bee pea ra haa AA, _ putot (wes) ree tS tee asset ojP - | betes ef om On ae a wal; a a A=> Python logted Openalors with _Exampla - B Operators aye used fo putform operations on values and u vowiables. These ave the Special synpbols thal Lani out arithmetic ; : t ° rs + and Joateal tomputakons.. The value the __opevator operate on Y Known ag Oprrand . 4 ~_ logteal And - logteal or - logtead not Uv Uv [v) 4 1 fatre Output Trtre—Output : Example- _a=10 ‘ b= 10 4 c= -lo O- 2 we 3 We « i} a>o or boo: paint (“ Etthe of the oumbew a T ots Lf else: = nr ~ 7 __3 a paint (No number ts greater than 0”) = aes s se 3 | a _if b>o ov ¢>o: | Heres 7 4 puiot [v eivher ef the number & greates_than_0”) ~ H else: . + paint [" No number u greater_than o") ately J ojP - Eithey of the number reatey than O ar No number & greatey than O WS a Example - a=lo uM} bz12 a] cz 0 4 i 4 tf aorborec: pxink ("Atleast one number has boolean value ag 4 Txue") ‘ 4 else: 4 pink ¢ AN the numbers have: boolean - value at 4 False") x OJP - Atleast one number has boolean value of True. - Logical NOT operator - woke with a Single boolean value. {P 3 te _beclean value. & Taye % Stehurite " Falee and vfte~ Nvisa, no Not x] True. & False 1 3 Sh False ofP True ofp Seerae yy Date sisiesssise oe ~ 4 Eyamplt 22 O10) : a tah cdanled value of ou Tue’) Wo nl (00 sa agen ok lh a Lt | not (a4 at[de2 ore a*}o§ 0)! saint | “io u onot divistble by eithey Jor 5") = —S Claes we patat (“10 y._ divisible Ny ithe gor 8") 4 dore bin’ o evalor_ = _. Bualuabeds ts ‘nol - we Youtable inthe ts ‘rue fhe thi poe: _nok - finds Oo _ false ra specified _ Sequence ane otherwie 20 Jest = [10, 20, 30,40, $0] if (% not tm dist): print (“oe ts NOT pacsent tn apiuen Jfsk!’) _ és f ~ else: b fn_given Jat” J paint ("= ts patsent din given dis \ H Usk =~ ty in ; - “patat ("4 y fs pyesent in qiven Jt") —F ' N 7 else: “~~ paint (“y ts NOT -pxestnk fn given She) + ra) t U yy : oP - a fs NOT potesent fn_qiven_list’. ~ y_ts saweink in afven Itst . S J i J —~—w ag -_\dentity operators — They ane used ito compare the object re — I ae am 7 a + T both the objects aned actually. of the same data hy Be and } tt = Share the same memory docatfon. 3 Tere.:: ane different. “ident hy; ccoperators codudh’ os = f 4 Ms’ operator - Evaluate to True if the vantables on etther side x. caer carr 5 of the operator point to Me same object and false t t v ' 4. oltisthualitess _a Exomple - “n= § ide] : 7 hes > porint (x fe 4) 7 >» td (ac) fd (uy OP = WO7TDYSRLET 2032 = IWOFONS 8 067208 Be wn ° «and y have Vales Hute, tn the given example, both the vautable %« an ¢ $ c 5 assigned to Vtk_and both share the same memory —_lo¢e pnts which why vielurn_ True. Sh es U - 6, [1K na apblaloe —. Evaluated ts folte_ if the vasfables on eithet side 4 o} the opwtator potnt to a_diffarent object and true othelwue, , t t 3 : | : Example - = 5 a. a 3 te type (o) fs nob int}; —* f we at “ ii wh a 4 puint ( rue") %e, 3 elses d pytnk ("false") - E #t Putnts Tue ° k me SG %, .J * oO — a TE (type (a) ts:not int): | bey ~ 4 paint (“true”) i else: & putnk ("false") = t ; a o}P- False sie wy Txue =) : ' i v tow fee * => Python: Bitwise Operators: — ts tz ' g . Operators are used to perform ° Ope i mA p ahons' on valueg S> Lars and variables. hese ane the lshectad d ftyumbole that cotey _ out auithmele and logical computatfong . the o value the Avi : — operator opetates on is_known’ ax Optrand . em a Cen: