0% found this document useful (0 votes)
2 views77 pages

Python Handwritten Notes

The document provides an overview of Python programming, highlighting its features such as simple syntax, dynamic typing, and support for multiple programming paradigms. It covers various applications of Python including web development, machine learning, and game development, as well as fundamental concepts like variables, data types, and control structures. Additionally, it discusses operators, input/output functions, and the importance of comments in code.

Uploaded by

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

Python Handwritten Notes

The document provides an overview of Python programming, highlighting its features such as simple syntax, dynamic typing, and support for multiple programming paradigms. It covers various applications of Python including web development, machine learning, and game development, as well as fundamental concepts like variables, data types, and control structures. Additionally, it discusses operators, input/output functions, and the importance of comments in code.

Uploaded by

Rajitha Sandeep
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
PYTHON Handwritten ™ i Date .. Indo d y= ~ = Python ua igh leved oe aE and wen 4 eld => fy by Lo wall ax__puoe poem = Jang te tm —_ tt is bet use xin applteiane ete. enibtc puoyeame tnenally Smalley than the othes wt development, Machine learn. puogrammin lal Brogrammers Shave Yo J iy ype Jielalively lets andthe indentation requirement ek Janguage , makes Heng Headable at ihe time. sth wen Simple Syntax & Easy to learn. ly 4 ded t J see ot patot (“netts") | ae pusipose Janguage {_Simple yeh uerg powerful language) v ta Application & Scripts Desktop _ Application z Web Application 7 Game Development = Machine Leerning ‘ Deep Jearnirig., AL + Big data i 1S. > ee Muttinaradigm Support x Say [ola Puocedural Style Programming [tke ©. — 4 z O0Ps. (tke Favan ¥ Funetonal programmtng (tke Uist. = Pat t Date => Portable _o¥ Plaiform Independent : ___= Programs are _kypfeally fest compfled Into an i ©, Otatemicdtae: tod einine thet Goda Wielvua 7 Me Interpreten: ES Pam Dunamfealty Typed 4 = m= 10 _4 ca tgeeta” 4 thon” ‘ This — i dtfferenk Jao c++ Bb Tava. tng 8 gue Statfeally Typed. 3 \n__python” we don't have to specthy fhe: vanfable 7 name. But the disadvantage & fn thts the bupe & assigned in__the yun time’ of the pusgram , to ‘there ate ’ f move chances of wun ime error. —>_Automatfe Garbage Collectfon \t means when ow dynamfcalty allocate Memory £0 you don't have Yo worry to“ veal?stng this memory - v 4 § > Popular Application Sutlt tn Python - Joutube j Netfifx',": duora \nshag rare 4 Dorp Box 4 i => _batot fn Python — q A_function & a sek_of some fnput from wa F t Seeae Instractons' Hak take 4 ado. Some: work on those Date .. ~ SJ posemstets_end pucduce some output - Example ~ pint (“Mette”) = __pafot (“welcome aafot ¢ patot ( “ope. -you are Ourpul = Hello Weltome fo EG rie Hope you are sofeyfag Python —> sndZA_ end and Sep parameters fa painkd) uy pxtat (“ welcome”, end =" “) pufnt (~ te GPG") é Output = Welcome fo GPG eorhrect End porameter creates space _and it tells » shoutd be printing after the painting. in sep pavanteten: when. -we have’ multéple f And input pavameters we use cep fo separate Hem. By default Wey ane Sepanated by space at ot wr ator (“1o", “ae, "2023", ) Sep="=") Output ~~ 10-o§-20a3 TOPE URAL Ra LIAR | 7 “=> NawPables fn Python = L Vasfable & a name that bused fo efor Jocation. Python vasfable 4 also known as J ~____-ffew and” used to hold value. j__In_python, we don't need to specify the eof Naxiable because Python & a ftafey language "and } smant cnough fo__get vantable type. Example = puree = loo I tax = 18 total=psifce = fositee + tax _paink ( total- pufee) Output- ing How vaiables wowk % X= 10 to|< * pe geeks" [gecks = z= “240 ao|<—2 it we Sa, wez ten aa SN wx Suna Ws $0 20|<— w ° paint {x} Op - lo —patot {y) geeks patal (2) ¥ i ao putt ts) ia ; L. | dol hte | al she lal ah le el cll al lal a la ab m2 10 3g at x) _ me geeks” - vy taker) P ~~ j op - 10 a geeks - 35 r NoTE - Using a variable without asigning ft cause error. » 4 1gning— ~ &q- paint (x) YY ofe- Name Error: name ‘x! fs not asstoned = = a 52 input (y fo_fython J This functfon u__used to _take inp ut prom the user 3 Example - name = ‘input (Eaten the name Sy paint | w welcome’! + name) 5 =m ole - Enter the name + Himant + Welcome Himant > Example - _# Python program for addition * + + ‘npul (“ Enter First Number :") = input (" Enter Second Number: ") 3 te o> fat (x) » yz tab (y) Hess wey FW Spenat print (" Sum By ves) Output -___ Enter Firsh Numbeyi> 10 Enter Second Number = 90 whenever we have to i —TypeQ_in__ Python ~ “tt fi “Type io bullt-tn function thal tells f of a “vawfable or a _value. ‘ lL fg a=10 3 bufnt ( type (ay) be lo-5 ~ : % bufot ( type(b)) 4 ee 943i 1 ke paint (type (ed) | OJP - f 4 =1n_python we use "None" to Indfeate that we don't know ¥ ‘ . C s Yhe value uel or we didn't aastgn any Value fo hu vautable > q \n_python these % no char type Ip you wank thar your should § a oe rte nytt Sel String fea" sequence 3 che fun (Type Carey) = 3 a J= [ 10; 20, 307 (Corray and dynamfealt s paint ( type (1)) add and wvernove thee. Hemi _ave stored to conta og 4 >Aueus locators) : Seat “ w ea : 7 pe Layee ttn) — eee va dblevenee & you can't gg. d=“ geeks" + paint (Jit (4)) paint (huple (4)) tink (sek (49) Gps Liga tes tei ed E ipa 18 Cg tes, “ey x modify once you trea tuple . These ave _temmutable) > bs [121 80,39} (Ser & a collretfon of thems Tr paint (type (s)) where all thems are _dieHack = and sct UW Jike mathematical Set) ~ dz fio: “gigs 90+" ide"y [-dictanaries are F putot_( type (a) mappings. Tha & a = collecHon of keys value patrs) > kq- Thems i _pyices xollno + harie:, f > pee pe conversion_in__fython 3 3 Implicit ExplteF fq a= lo gq a= "38" a Je 14 dat(s) ee ee f= float (4) d= True pafotG) } ez atd paint ) paint (e) Xo = v5 op - 14s y W 135-0 Li 5 } — t sitnt (bin (a)), a sink (hex (ay) ak (oct (a 1 i Eg ee i i OP ~ — Obin100 so — » Oxy 5 ¥ a 0084 ae Comments tn Python ~ We may with to deseutbe the code we develop. We 5 might wih to take notes of why a section of suttpt py i for frstance. Formulas pyocedures and sophisMeahed . bustness Jogies are bypPeatl explained with comments, # T UP 4 Single -Jine comment - # a Malt? -Jine comment — A ioe NE 7% a _ Doc-ching - the string enclosed th triple quoter é that cones immedfately after the detined f" ane called Python Docat¥ng. 4 q Ss => HP else and elit tn Python — 6 thule _tome luau ta steal Jie whan we need lo & do some Speciffe bask and based on some specifi é Conditions and, we decide what should we do next. Simla thate coma a sthuaton tn Hogrammine s wshewe a specific tak ts to be Peiformed if “Oo. spectre Condon true. s Sheraé L, ~~ Mate In__guch case cond?Honad WT CondiHonal statements Wl condiWong’ _stalemer Bee tt Tipe ati statements. asics aks - fn thes iP the condition & true then f Sf_-statemeal the _elte pout executes . » 5 coat executes thie S$ Syntax - tf condition : es % # Statements to execute ff y # condition &_biue Flowehasyt y ; Fal z us x Tat 5 y Body FY = y Statement fust below] d F 3 Example - if to75¢ g puint ("10 & greater than 5") i puint (* Puoqram ended) i OJP - 1 U__qreatey fan S$. fragrant ended E Sparat if-else statement ~ tn conditfonal, ff Statement the additionas block _ ed_as_elte statement: whteh perform. a al thts block ff __# condition th lue ele: a, 3 # Ereeutea this block if: t # condition ty false Flowchayt_~ = False a fs FBisdy- oF eae] 4 ——_ : ; zy ¥ 7 Example = A238 > if m=24: paint (“yes"') else: 4 paint ("No") 5 Fxample = You_con alse chain _ff..velte clalemenh uth more. than® one _condilton. in ‘ detten = "A" i ‘deter == "@": 4 paint (" JeHea ty 8") qi elses 3 TE deter = ="c", _puint (" deter eh yp statemint =f statement ean alto be checked tnsfde Ss “a a ° o SS they if statement. Thu tonditronal _«tatement u called a i Jha means that fnnen if conditon will ~3__nested ff statement. be checked only if _outer if condition fs true and by the, we can. ste_mullple condtifons lo be. saltstied . Syntox - ft ( conditfon I): ~~ >» # Executes when condition |G biue it (condition 2): > # Executes when condiHon 2 true z # if Block & end: here > if &_endih # if Block & end hue __Evample - num = 10 a Tt num > 5: = puint ("Giggen than S“) oF Uv > tf num 22 153 5 wint (" Between and 5") 5 ___ojP-___Biqge than § v Between S and 1S HE-cltf Statement - shortcut of ff -else_chafn, while using ipeetit 3 3 statement at the end else block & added whic “& _ §_peiformed if none of the _above i-_elff statement true. Seat Syntax > __ if {eonditfon) : Statement _elit (eonditfon) : Sholtmiinliss. Soar Sn Ae z elses — statement —4 wai a Exampl ~ deter = A if dette = "QM: 4 pint ("Jeter &_9") 6 elif deHeu = = Ne: 7 puiot (“Jeter & 0”) * allt Jette == "1a" : a paint (" detter & An) - else: paint (" Jetiey ten't A,B ore") a t . 5 : a O[P- Jeter tA 72 Aallimette * onesatorgi= The gNe uted to peform mathem-_.. es = val Yo vol 2 = putat ( ec) > op = 3A Exponeatfatfon Operator — ** & used to raise the first operand fo power of steond . = Example - val = 2 pe za yal 2= 3 > ves = Val ** vaio ae. ae print (ves) op ~ 8 * Seerat | © Floor diyfifon - // % used fo find the floor of tn ea when first optyand ts divided by the second. Example - val = 3 SaaS RS ., pss NON Oi tha a Hes = val t // vata i —~ pool (es) Baer is Brest haD ojP = 1 = = ifs _# 1s Python legfea) Opevators with Eampla = . H Cpurators aye used to puiform opetaltons on values and — ¢ frawfables. these ave the spectal” symbols that 0 and b>0?: aoe = 2 ete: ——— ~ _patot (eAMleast one one__number_u_nok gral oli than 0 realor than 0 ae nok. qrealey than o. Uv sy -__ he numbers gue gu AHeost one number u ST trample - a 10 ~ 3 bet b cz 0 ~ “tha ond b end c: ~ __psint (* Atl the numbers have boolean value os True”) po else: __puiot ("Atkask one number has boolean value ot False’ wa o or boo: ‘ x ~ = oe (2 eiben of the _numbew grtsios than 0") else: 2 pain No_numbes ip _b>0 or cro 3S 3 s _puinh ("ether of the number & grsatet_than 0”) else: punk [No number a greater_than 0°) DIP: einen of the number Ui greaten than O No_number fu_greaten than _O Example - as to biz ec: 0 agorbore: pint (“Atleast one number has boolean value at Txue") 4 else: pfnt ("AN the numbers have. boolean value as False") D/P - Atleast ont number has boolean value of True. Logical Not operator — works with a _ Python Bihuice Operators. — of or Operators are used to perform opeah’ons on valu and varicbles. hese asie_the ‘spectal _sumbole that can out __anithmetfe and logteab tompubultoad » The value thY operator operates on “is_known cx Optrand . ~ we wiwise operators = Q_Sitwise a ~ : ME scat a 6 °, ny a)- Bihwise AND (2%) = Return 1 tp both the biks ame 1 = elit_O- . as Example = a= los 100 (ginary) Ww b= 4 = 0100 ( Binary) ; ab: lolo ~~ : SE loo 5 = 0000 _§) = 0 (decimal) Ty pikwise OR (]) = Returns 1 if either of the bit & I else o. + Example - _@=10= tol ( Binary) = ot b= 4 = 0100 (Binary) al = lolo Ww 1 =) olo0 ». = lilo >= = 14 (Decimal) - 3 d= Bitwise_NoT operator (~) - Returns one's complement of the no = Example = Q=1o = 1010 ( Bir wa- l0lo > = -(loto +t) 4 =< (ott) ges +. =-1 (Decimal) 3 a)- Bitwhee (xoR) (A) ~ Return | ipo one of He obits fs Land the be other & 0 else yeturn 0. 3 F Specal 3 3 Example - a> 10+ 1010 (Btnary) = ata bs Y= o100 (Binary) ° =14 (Decimal) Example = a= lo “ a4 . ° oe re # Puiot bitwise AND operation E~ + print ("aa be ob) ~ i # Pyint bihwtee of operation - 1 paint (“aje=", ays) = | # Putt bthwise NoT operation ae i paint {wa="; ~a) : * i # Pato} bitwise YOR "operation ° ! paint ("ab =", a Ab) & — ojp - abLb-9 alb=iy4 o Oe -t ae atb=14 & A & -@_Shitt Optrators — There Optrators ave used fo shift the > bits of a number Jet or wt ht theneb multiplyin ee ya or dividing the no. by hwo resp. Shey ean be used when & we have Jig rmultply or divide a dumber by two. 6 —9)-_Bihutse Ri Shift (53) 7 Fo the bits fo the sufght and fills 0 on _votd. Jebp TMs ys Case of a negative Number) vas a Hesult. See ey ° fo. with 7 Te Ihe no. Vin the 3@m effect os Sn ~ Similan some Pow of hyo.

You might also like