0% found this document useful (0 votes)
0 views61 pages

Python Unit 1

The document provides an introduction to Python programming, covering its history, key concepts, and fundamental components such as variables, data types, lists, tuples, dictionaries, and sets. It explains how to use input functions, operators, and provides examples of basic programming tasks. The content is aimed at B.Tech second-year students learning Python programming.

Uploaded by

divyanshicse2025
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)
0 views61 pages

Python Unit 1

The document provides an introduction to Python programming, covering its history, key concepts, and fundamental components such as variables, data types, lists, tuples, dictionaries, and sets. It explains how to use input functions, operators, and provides examples of basic programming tasks. The content is aimed at B.Tech second-year students learning Python programming.

Uploaded by

divyanshicse2025
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
[Link] - Second Year Python Programming Mopute -4. Lnbtoduction To Python what A pxopxamming ? oe i a way to dratruct the computer petfoum vasuous tOaKS. Hustony of py thon Python" is whi used general purpose Migh devel Pog 4amnu'n dan eSt wos tt dewgned by Crudo Van Roum 4 [Link] developed “by python Aoptuane foundation. aS was rane developed — fon emphasis on code Headabsuty and its aynta allows progstammers fo ane concep in “foo Linu of code. * python 2:0 wad weleaed On 16 octdbeH 2000. k Python 30 wos Heleased on 3 December 2008. fA Lotut version 3-12. The Language’s cone phitosophy edt hos an onthogonal, exputit and nuruimalist dewgn thot maka code easy 4 understand ae eauy to predict. & Python Ee compl pres a simple ats app ey dpyutatie = specific tools er Eee set modulax LbHary. tand ait * (© scaned ith ok Scammer [Link] - Second Year Python Programming Fithon_vaswablu : A vamiable is the name qin pa memo Jotation th a pHogxam . Vosuable ws Like a contanee ue Jp Atont q value. fon example:'- A730 b=" Age" Cr Wag Key words ‘ Reguronda ane the serenved woHds sh python, ~ © Eq. impoxts bHeak 144, ete ddentipivu: ddedifien db a clam / function | vaxlable name. Module os othe object. Rus fox defining. a Vawable name >A vouable name can contac alphabets, digtts , and undwrsuon es . 7A vosuable name can only alphabet and undexscone. 7A vosuioble Ataxt with an Mame can't stant uuth a digit. ?7No = uuuté spare us allowed tp be ued inside O Vosuable name . Cramps of few valid vaswable names ane- abe» twoz3 , —code » thHee ? tran, (© scaned ith ok Scammer [Link] - Second Year Python Programming Datatypes + | Python dlackadipbes are ued 40 deftne the type of a vaswable. 4 deinu what type of data we ave going tp stone 0 2 vowable. Te data type one :— Sndeques (Numer. dat otaypes Ploat complex numbuts ED) n ot Sy (29 Sequence d MS et e ‘39 Boolean - 4) Dittion CANCERS (ince Note ¢ typetd fundion 4 used 9 detenmurie the type af Python datatype - Python Ba fantastic danguage that outomale ay, Adentifpies the type of dota for ws - Example: Qs Qa => sdentifiea'as a lau sfdendipsd'ar claw < {leat names "xyz" _» dient ‘Name’ as claw Complex- hold complex — ruumburs ae ( Numeue Data > Python, numeud dota type wa ued to hold numeuc yaluer, Integers, floating ~ potas ruumbers and complex ruynders . They ane defined 04 anit 1 float and complex _elaes un python. ; > int= holds signed _antegua_q_non- Lunited Length - 45 detimal points . num) = 5 a poutat (rum i," ie type", sybel rum £3) ns numa= 2-0 pound (rum a , 4 of type") tybel num 2)) num $= I+ yf oP ee print (rum 3, ‘us of tybe 's tye (rum) utput : ee Sas tybe < days “int 7 ae 2:0 ds ef Aybe Cit dj) Uf type THue - Aybe (a) = tpi | — “a Loss bootty oe T= Sets — Sets one ted tp Atohe multiple item sn a sénqie Vasu able . nee ce Wh One of + butt -nh dota zypa ta python A set 44a (ole ttn uthtich 4s Whoxdened, Unchangea wundexed. ee eee Oupuicote tema ane not atowed _ You tan___emove Ate ond add __new tem. thiset =€ " apbie". banana”, "hyoug’) | punt yrinee ) z se utput_ Liopple's' banana’, ‘chyvey'y those 2€ " apple" 1" banana”, " chouey", ” Able” y purt ( these ) ‘apple’ jt banana’, « chuvey'} (© scaned ith ok Scammer [Link] - Second Year Python Programming input) Tis function ud4 take the input ftom _the user _and comets i wit) A Attusig. The type of the hetwmed object ony Wil be < dam ‘stn’? tt dots not evaluate — the th (on. 7 dt just _Metun the complete Statement 4 _Stadng._} Fon trample, a Wython prowde o biwt-tn function called tnput uduch taku the thput torn the her. When the Lnput futon Ja cabled it stops athe _pxognam and watt forthe Lut en's Anput. when the Ut _exprtwa enten, the Hume and _Hetwru what the trample : < val= _unput ("Enter h_yolue ;® pound LWAL) ta Sa : @utbut Enter selrn name xyz XYZ vol= input ( enter yuh vou ii Prt vot) ouput z Fnivr Youn name xy2 NZ — ee -- [Link] - Second Year Python Programming How the input uncon _work4 th _pythan : e when unput U) function txeuure prs fleur UU be Atopped untit the att hag given r The te oh Mmtssage displayed On the output Auteen 4 04k user 40 enttn an input Value Uv abtfonal rt: PHomp+ 5 wuluich uit be psunted on the Auteen is Optionas © whosever you tater ad dnpud » the abut punch on Converts wt _uinte 0.” strung af you _tnden_an_ nd egen Valve _AtéH Input O function —conyetta dt tno 0 Attung. You Need to Expuiutay Gwent JA into_om _imiegen din _youn code __ din’ —typetoating.. ie hucmbu = enpud €" enter the _ruember :) —— prund (number) . ae = utp ut ‘ae enter the rusmber: 423 - 133 ee _nunbur=_impud ("enter the ruumber tn" 7 Outpud pluie Crumbod tnt Ut the number | ame = uiput Center the narre int) acai tz E } CNN eee : prone C type ob number" type ‘muarsend? Enter te name uw " d au pre f Type Y- name" * type (name tat shybe of nuumber elas ype of name <4455'sty'7 (© scaned ith ok Scammer [Link] - Second Year Python Programming Raw _unput C) | Tals Junction workt 4 alder version (Like python 2x). Tus —_funclion takes hau what is typed __fxarn the Key hoard, (onvuda it ating, arid then _ petufna J uk “te tht yorinble sm which we wont 4 store st Mumber= now. input (" enter the number sn decimal”) print ( nuamber) eutpud Mow drput 4 pot detned Woute program to take number From Lue andl add there Num bert Me INtC inpud ("enter the Firat muumbur") ) point (k) Y= tnt (input ("enter the swond number" )) Zs tyes Pun” " the sum of too Mmumpen™ 2) Write a progam to fund aut the area of Hedtongle = int (input center the Length ef Meceangte)n) pHint (* the Length of Mectongle |X) ari Y= ink Uinpub C" enter the uudth of Heetangye\n") _ prunt(" the ubdth of ertangie's 4) oxen HF : print (aMea) out the _puimeter_ of WHite a phognam to _fuid Heckangle . m= intl amput (‘renter the Length +f utongieln’) pound (« the Atngth 4 nectangle X) ye"fypurcn enter the uuelth i Heutorple n°) _ punt ¢ the uudth of Heetangle oo : puus aecaty) punt (Pod) - Waite Oo pHogtam to fuid out aed and. puumeter 4 a squone A= float (Input ( enter the side Bf the squanetm™ purit (tthe Sitle of the square a) alien = Ata prank LY the aviea of the Squane" 0100 7 puumeter =F ta print (" the pucimeter of squame', pouimetery Write o _pHogxam to find out the anea and Uncuumperente of uncle wr as Me Ploat( wnput ("enter the “adun of Unee In) ) proud ("the adder of wiele 1X) OHeA = Rit AHHH puumettrs dt 294 4H ‘ prandts the ace af curiute anea) a point (the puumeter of urcele’, peumew) [Link] - Second Year Python Programming WHLite a pHogHam Jp AWA “two Muumb 1 WA th “t thund voxuinble - 1 = antl amput (enter the Flue ruunber\n" )) Y= unt Cinpub ("enter second — rueunper iv” )) peut ("the vatue of X= /'r Xx) pount( the value of ¥" 4 ) z= ai ie fee prune ('" the value of % agter swapping, punt (Phe yollie of y often swappinry ci WHite Oo pHogHam tp “swap two “ruumbur wuttheut usin third’ voHXtable % = fnt( impute" enter the Fistct nuunber|n'')) Y= Tab Cinput ("enter seeond numb en'in’?)) peut (the vale of | psunt (" the valle 4 Y= ue Ate i hh i a. ke xty a a oo pend C* the _youlue 4X after swabbing, x) = peut (" the volue af ty after swoapping, 0) [Link] - Second Year Python Programming Wréte a pXogstaun tp und cut simple ant erest Pe Ploatt input( “enter the psuinciple ")) Hz Ploate input’ enten the mate’)) — {= Ploat( inputl’ enter the time ")) Siz (pk Het )/loo punt (" the simple inrevegt > st) Wuite a_pieg am to Find cele 40 Fahrenheit Celery > int Cinputl" Enter the temp viatwie i'n _telerts w") _ Fahnenbed = [1 ge Coleus )+ 32 yp is print” Temp exatuxe tn Fahnenhe it !%, Pahnenherd Write a px ogtam to caludede a Yerege of two numba Qa fatlinputl® enter bree number )) ‘s Jaen avg> (ath) Jo paint (avg) [Link] - Second Year Python Programming _oputatora sn python operators one ued to perform opexalioru on vasdables and yolue. -oputand. An operand i a value that the openatox needs 40 Compete a tsk. diffrent typeof _opetatons one — > Asxthmetic operatoxs — Comparison operators — Assignment op etatoxd —» Logidal oper ato¥s — Birure operators ~~ Membership operators > special operators =>: Jdendity op ratoxs Aivthmelic specatons Atxthmehe openatoxa ane used 40 execute mathematical Functions - in python uduth fndude, addition , subtxacton, multiplication, © divéston, etc. | operator. Ducsupeion | Example (+) plus Ado two opexands 5+5=10 (—) Minus Right hand opetand is : Sing From the left - 20-lo=10 hand opexand. (#) Multiplication | $+ multiplies the values on aeas4 either side ot the operands. (© scaned ith ok Scammer [Link] - Second Year Python Programming oputatox | Desckiption Example (/) Divéaon | deft hand operand diveded : by suight -hand. operand eau (Ye) modiua jt dividu the tet hand rue operand by x1 Ri hand one a and olay * Hel a Hemaind er. W/) Ploox Diwasion that elt, th the 50/2 22:0 divaaron uthole mumbor bung. adjusted dp the ty! in the number Une. ( # *) The left operand & naled Jo to the Exponent fo the power of the sught Power ot 3 Jo ¥ #3 =400 loon Divivon > Flo dvacsson ts & noumat divesion operation, except it Hetwu the donget possible integer. The anteger can ether be Lea “than the noma divelin output of eqval to it. The Flot diviién is an opetation 4h python that QUows wi to divide two mumbsu and ~ Hounds the Heuultent value down to the neawut integex. The Floor division ores thxough the C/I) spuraton. loon function Ja signufitol by the L) symbol Ln mathematical tekms. (© scaned ith ok Scammer [Link] - Second Year P P ig et uu now undeutand the working q the Floon diusten Fou example: L 36/5) 1 performing the clivisaon $UUt we will divide 36 byS O66 fine 42: 2 Now, we wll puyotm the 4lo0n olivision on the obtained value te 74 (F-2a =F Let ws now undeutand the woKkiing 4 aul authmelc opetators via progam oF code. y= 20 output. puint( a/b) = ——> 16 psunt (a/b) ———s print ( "Kt ye" axty) punt (* y-w', x-y J 46: 94 — xty= 30 ; aoe LO) sunt (" an Pie Gah ey-2 44), — x Y= 200 Prune (= Xeye™, Xey) —— apy = it pune ( Cet ey ——> x1e#y © 1000 Python Programming [Link] - Second Year byt dn python, the compatuson opexaton 4 used to analyze Uther side 64 the +hen different types o — Composudon ( HelodionolL) bperators are - valued # deewdes the elation between ) == Equal @) = Noe equad (7 gveater than (4) < Aes than (9)7= Gimeater than on Equal to (6) <= Less than ot equal (LD Python (==) Eyal compaxtion operator The equal cpexatoy is used to compane the two values and 10 give the Hesult whether they ane equal ov not, 4 both the Vole ane equal , then 1 gives the Hoult o4. Tat, gy not False. Example: x =L0 y= 3 Ces punel" x==y", u==y) Reiag b= tao psunt (“acce"s'a=>b) [Link] - Second Year Python Programming (2) python (1=) Not Equal comparison openaton Tha not equal operator id wed t compare two operands and setuid a THe Statement . G thy axe not gual and Foue ty they one equal. £ H=lo0 ut } po utp ut Prud (oc tey gis leq T, ere Yo, YD) ley Tae b= 130 puint ("al-b" al) a+b Fala (3) python (7) gxeater than Compaxiton openaton Tub operator Ju masindy used tn python to Hetusn THe the L4t- hand vabwe GH eaeUy than the sight one 4 ES sutpat. Paint "a7, ary) 7 y Tue (4) Python (<) Jem than compartson Operator “Thuh operatox compar the sught- hand opetaion uulth the tt -hand and if the ght- hand ene is queaten than the deft- hand one, 4¢ Hetwon tre Statemen, ce ase sutbat = a ee a i a — Ut a= chut6) b= ditt) L pune (4) Mae Ptunt Ub) (© scaned ith ok Scammer [Link] - Second Year Python Programming frog Hampiing cycle fox python Python's peop Hamming cycle a ei dha Ahoxtor than thi of tHaditlonal pxogxomnran ee dn python, there axe no Compile" o4 Link stepr. Python pregsiams Adin Lmboxt modula at HUntime and we the _ objects on contas. Because of thi, python pia ia wun mediately after changu ane made. dn coves whexe dynami mode ndoding tan be used, tH 4 even pormibye” 40 change and Heload posds af & Hunund pogo —uuthout " Mepung id at alt. pythods impatt on the Boy cones wyde uaa FoLL ours | Stat the appuiratien Tut Behavsaun Stott the appurcatien Edit pH04Ham (>) Python's _ [Link] Ot ate te (4) Python’e prog xamnuig wyce F Heedurg, Since, python iu unterbyeted, there Ua Hapid tu noxiound after pHoaxam changer. Ard, because python's pHaser dy embedded “in python- based system. dt a tay to modi py oo id odlaty Deere at 2 (© scaned ith ok Scammer [Link] - Second Year Python Programming What uu IDE An dndeguated developmart envionment (106) A soPtwane cotlore that helps progHammuu develep Software code gHuenty. dt invreos developer productivity bY tombinng —copabi tits Auth a software cdiling , butlding , testing, and packaging un Gn eoly -to use Oppliiduion . Juut as writeu" use text edi and Ateountants use spreadsheets, softwane develope st TEs t moke thon job casi . why IDE Ju impontant 7 Code editing automation PHoguammurty Language have sul fos how Atatunonts mut be “Atuuctluved- Bacouse a Tp know thee Fut. 2b contains many sntelldgent features for toma Teay wxiting on edliting the sowie Code. Syntax huighanghasi An Ibe con format the wxitten text le automatically making ome words bold on italée, © ov usin dujpetene Font cops, These veuuial cues make agwue code moe Henlable and gave shitant Feedback about Occidental —Aynt ak DH. 4miduigent code —_ compdetion Vouoly senich stem show up uthen you start typing. word vA a seanch engine , simiuasly, an IDE LAN make Suggutiom to complete a code ctatemet uthen the atvelopet bequiy yping. (© scaned ith ok Scammer [Link] - Second Year Python Programming Reba ctoxin Ht _ Code ndabauhy J4 the pHoces of sutsuctwung the sowee code to make if more opulent and Headeble uum out anne ah coMe functionality. pe, tan auto- me narton Jo / Adme ettents qLieusing developeu to umpyove theLH wde uitkly and easily. othiy team member undeutand Headablé code Faster, uuhich supposes — colLabon ain unithin the team, local butld automation IDEs tneiecde — pyro naummen — [Link] by pefoxmuy Hepeatable develepnders tasks “that one typicabup post of tv code change - The "Following “ase Some. examples af rea voding. tua that © Om IDE coHid out. Tuting > The Ine atious develope to automate unit tebe Abe before the Aoftwoe J ante nosed uth ather developer's code and move complex Petts tier elds “OME SUN , Debuggin > Debugging us the pHoc es 4 soy ero on fm ‘testing meveats. tne & the biggest Values an Ine for " debugging puxpora 4 th ou Can step Hut the uates the by Lay ay ans” Qmd Ju pects ode behaviour . Some python Tne 7 Pycharun — Spyder — Pydev — Ipie — VISUAL STUDIO © seamed ith one Seamer [Link] - Second Year Python Programming Pushon is comasduted ar interpreted tang unge uy python uh indorpw eted angiage? ; The most commen ayurtg y which a alto publithed 1” vue books, 1 that python 4 an untupueted dang vag » however, the Iwdden fact & that python uh bor compiled and tatexpyeted. Tes rught cere cont ads ctor at firuts but it's mportant-to undeutand how Python's compilation an uvatertp Het atein work together, uchen you wHite a python progam, tt ta snitiallyy o~ Sowice ‘code ocr. Thu some code need 40 be transformed Into an executable form that can be executed by the Compute. Thee ate fo ody to do thu: Compilation: 4 Lis proce » the souree code uu tranuated into macruie code ox bytecode ahead of time. The tag compiled code cam be eveulted danecthy uuu vet Ou fh proceing . Python! Use a compiler ro Avavuform the “4ouwee code ftv" bytecode, whieh con be exeuted by the python vintuol machine. Thus ia how python code etecuted tn” envimonments Like pychatn , visual studio Code, ox other (DE es) that Use python’s Statice analysis tool Sniorpuet ation: in thi pxoced, the Aowce cede ia interpreted and exewted dttect the fntepneter at smuntime . uthen HUN a thon 4vipt fxom the command dune oh an intevatve * shell, the intenprteter sical the Aounce ode # exetuter 44 Line by Line, Tha 14 how python (ode is executed 4th intexacive envinonmends Like Jupiter notebooks, on an ued apple cations whee — python tode va execeited on the Avr Ade . © seamed ith one Seamer [Link] - Second Year Python Programming what happen wthen you put semicolon at the tnd 6 python’ statement The common meamng of & semicolon (i) un VOHLous programming Language is to end oF discontinue the cusent statement - Jn prog xommung Aang Hager Auch a4 Cy Cte 1AM Java, ity Necess tp use a 4emicolon 40 end & dine ef wode . However » Aru sx not the Cate tuth python » ‘ Sericolon tn pythen aignape Beposation sashes thon @umunation. 4 qliouis you to weitte multiple statements a capt e Ane. pout Crim) 5 poulnt [" nelio'’); prune (« bye") udput u sh $090 $n thd example, we'll t 0 Loop thou s Statements —Aeparoted by ta semicolon and ee it the Loop prints both ov juut the pout one. fou i un angela: Outbut print ("Ys Hud Pink 7 pout ("pero 1 Helle Het Helto He Hon will thew an voon af ft 7 au use a serucelon to stpamate a nosemal ekpretsion Kom a. block siatement 1e~ Loop (© scaned ith ok Scammer ae [Link] - Second Year Python Programming what type Aanauiage is python Python ua an snterpyeteds object -omented » high jevell PEG Mee donguoge Uuth dgnamnic semaritin developed b Guide” Varn Rossum, $+ “Long oiqunally, released an 35t Designed jo be coy ai wellag fun, fhe Tame Python” iv "q nod to the Buitih comedy, group Moni Pyrhon , There axe some base element ef python Datatype opeiaton wwuaoble Function Key wor ols Toou to find bugs and perform stadic anoiysis weutting effievent weliable, and recone cede heap valued tain software development ne the op whose of python prto Hamnmwng , an Y ora fe wecerd jos it has! become inoteaaing vmfourant’ for developers ‘wo eruuve devi tede vi UION- gute seuits and optinv'zed - However, momyatly cnupeeting eveuy Luin of python twde can be daunting and time Loruumning .. That fs here Static Code oat tom into play. static code analysis ih the puocedume of inupecting. Appucatien source code uu'thout exeuuting ity de detects potential euros, Aecruciry fia, © seamed ith one Seamer [Link] - Second Year Python Programming Benefits of uring Atatte code Anglais fan python # xdenti}y pugs sn. Atagu ‘ cabin co oun ot aaa a * Refusna Instant" Feedbarks * Reduce technical Debt: Static __tode an ay sis tools fon _ python “pychecker and pylint one the AtMH analysds tools thot help 40 fund bugs An__python. _ t= —> Pychecker is 0 opensource tool fon state analyrd that detect the bugs from _sourtte code _omnd_w — about —.the style and __Complenity of the bug, = Pyint Ja __ highly Configurable and ut acts tke _spectad — prog om 4p dontol —wonnwigg amd error it hi crm extensive Configunatien File pylunt alto an _ Z tool __fon_St code nobysu jt Looks for mn OU10HS and iu uised for Chae Sa aa Atngth sf each Prtog namaung Llbe de Check the Vostiable Marne _atconduig “0 _the project Style. 4¢ Can also be Used as a standalone proprom, it also dotegnaty uu _ python _|Des Auth 4 _Pychonm, _spyden, Eclipse + Tupyten > _Puchecken _can_be Aimply drutalied by vain pb pocka: pip. Antal pyunecken . a pip dnutalt pyunt. : - (© scaned ith ok Scammer [Link] - Second Year Python Programming Featwtes of Python open souxce and 4Hee 4¢ Us an open- source Language cwuluth mean that ome (on download it, we tt» and shone st. Mowevers it wo pyle of cost, . sbject - owented tt supports object - ostternted progam ming Honeys featune, fox exampte, ~ the concept f° object and “ claues y encapsulation, imhestitance, eter @extenatble in Nature dt 1 edteruible in natuve usuih means that we tan Wie python gode in other domquaye. fon example cy Ct+ abo cam compile that wde ~ In Coy (tt. o Integn ated Language we can equity, intey Hate tt uulth they damnajoages such % Cy Cttatt-Hence » "it Uo an ee Lomguage : ojnterpreted Language dt cues an interpreter fon converting. the Source code to machine code. Thu mean thar we execute the python code sure by. duie. Henee, at become eon do debi. the exo & solve A, ° ee Stondind Ubs fe uhuosuea —contaun © psrectefined mo dul Junction for certayn 40K. omd (© scaned ith ok Scammer [Link] - Second Year Python Programming Boolean Expession Boolean expucarers ae the expnemioru that evaluate 4 condition and seule th a Boolean yallit re- tHe on fale, Ex tavb and arc) ta Boolean expression . At Qvaluates the condition by com passing. Pn 9% cee than ‘b? and alo if fa’ ‘as greater ‘than‘c’, 4° both the conditions oe tne only Then dou the Boolean eApHenon seulk 4 tye. gp one eondi'tion ju not due then the Boolean expweition weber seule tn Pale, Booteon espHesair) ote MUHIE SUIT Cale eras Cand), (01) qnd (not) Example» (x71) and (245) -MetIM teue YE bom the epndition 1. tue, re: cp the value yx? 44 between 4 ands are 2 CUA) on ( XJed)~ netwim due af any ene tonditin is tue fee. gither Xi divds'e by Atselp OR Uf *%" is divesible by 4. + (ueso) — netwins tHe 4p the value ef Xx’ Js - No * other than ©. 3p the value of SK? uso then it Metumna fale. Mie Ohi Rae a z=lu7t) amd (%<5) punt (2) False X=LO 1 Tue prunt (% 7 22 64 y<2s) (© scaned ith ok Scammer [Link] - Second Year Python Programming PEP PEP C Python enhancement proposal) us Like suggestion box {0h the Python prog Mammuin Jonguage. THs" way oH people who wok __on__Pyth’n_tb __ AUg get huw_4deos 04 thang _ to Python, and. tt helps everyone Acs, plan, and decide 4 _ those _ydeod ane _good {on __python.. a duut Like when _afou have an _—_xdea. you __wute it down and shone 4+ _uuith others. Tn” the othe Puthon community, PEP. ane Wed +0 _wHite down ____ and shawe _s'deas Fox —making python better. They kplan what the adea 44 5 thy d's. _9bod uid ea. ond_ how tt would _wonk. Then, ~ the _ python Community suks about it, Qnd if most people agute t's © i good _1dea,_## __ (ght became _o._ 4 python _| _in__“_the _ future, - 4n__simple__tetru, PEP uo. ond plan _winptovement oh _ntw _Featuxes For =i Python 1 fut Like a dug guition _box Fon Youn Favourite — pHing Ahonen ae i Pep Stand fon" Python Enhancement _PHoposal’’,_ Pets ane design documents _that _ paondle information _ to__the python Community pit describe 0 Ney Featute on umpHovemend din the python Prtegnamnmning | Aanguage . mapa’ (© scaned ith ok Scammer [Link] - Second Year Python Programming They ort the psy mecharaamn Pon proposing and dusesdding. chan to__ Python's come Aang uage and afand add Libnovy. aie The Pep proces 4s wed to Avgged gnd olebate _ Adeos, document the desrgn ahd inp Jermentation _¢ L —hew Feat ues, Qnd th many core, seach 0. Consensua__y'thun __the python _Lommunity before change dd Acrepted and intayponated _‘whto python. _ PEPs toyet & wide Monge 4 Senta enhancement to the development proce tsp. PEP: oe typical, authored and submitted by python developers and enthustouta _and go Htough _a_ Mev Qnd__oppHoval pHocem . = om Some Common typed of PEPs Include. (PEP Sees eZ PEP. oO - ___ PEP ase = __PEPI33, ete (© scaned ith ok Scammer [Link] - Second Year Python Programming Pep @ PEP us python enhancement proposal that outline the _Atyse Pon wrung. clean ond _neadable python “code, 2+ provide a set of conventions amd. wuidelin to take python code _conséstent and easy to Undewtand. Following Pep & He commendation 4 _ conudeted od fottice and help, eruune that pa tode sa xe Occesible Ond _marararnable. _ Hene one dome key polnta From _ Pep Bah plow Aanguinge. Indentation: Use + Spaces Fon each devel of indent ation, _ Don't sue tabs. (onwintent adentation make youK code dook neat and onpanised 7 Manumum Une Length ; a Lint each lune _¢f code _to Q maximum of 79 chokorteu {on code, amd 72 chanacter “Whitespace; Use Atngje spore often comma, catoru___ and zermcolons» but “nat — dmmedst boxe, Avoid txbyoneowt _Wuhuttspace ¢ t-4- at the tnd Lo uit). Comments: write tomments £0 esplowi complex. On Non= obviau poxts of you code. Comments should be dean and concle. Use complete sentences cmd Follow a _tonwatent cyte Fox ate commen (© scaned ith ok Scammer (eadability Luhuite ab ag [Link] - Second Year Python Programming How memony dh managed tn _ python Automatic Memony Allocation :__uthen you mente a Nt object sn python —Ce-g- a _vosuable) , Link’ ductonaxy, fC) he _memoxy fow "that object tu attocated from the piuvade ie eee toe sf thus Memory —__— aLtocotion automatically. - Memony Degtlocation ; when the Hqewence Count of an___ object“ dxops 40 Zero (1'-e- theve oe no mowe seferenc fo__the__ object 1, Python's _ memos manager _eliovated the memory _oxottated _usith __° that _cbject_. The _prioceas —duutomatic. ond tramupanerd. 40__tht_putognaromen , Gronbage collection : Gioxbage tottection vit _the __pHoLes of Hemoung the _untued _“yatiabie/ name and Preei the _MemMony, . 4n__ python — gaxbage —colleion —uis_perfonmed based on the_ tae feand mechanism, Crarbage collectoH periodically _thecks __ nd. removes _the me — From ___ memos, uhose___steperence __tount 2tH0, Memony Leaks; In some Coser, 1 you _vieate cineut Hefexcnees OM _marritatn _nefeencer to objects _uunneceasei you. On _tncownreH memos feaks, Thele ave Altuations ube objects ome NOt properly dealtocated _becartic yhoy _ wefetence _tount even neacha Zero. at's ewemtras to. be mindbut of code #% _ Unsure Phat yout _ ah Heper ences app xopsuatelg to_putvent memory Ss tok! See a 1 ee =n (© scaned ith ok Scammer [Link] - Second Year Python Programming PsuntO, Puthon pountl) functlon. prints the _Metsage tothe AtH een on othe Atandasd. Autput device, syntax: point © tvolue (5) aseps''s end =\n' > file= fute, Fuh = Flush ) Paxtomel ons : 7 - Values) volur, Om ou Luke + Wwe wll be_ mine boa athig habe prunted, - - ep = separator: optional) spusigy how i»stpanate He objects, ip thee _a_mone than one. Default i" * tnd = end (optonal _spaity uhat to print at the end. Dea i — file: C optionar) An ebjetk uuith a “a._waite_muihod . pepawet is stdout =| — Flush: _Coptional) A Boolean, specipytng if the euupud wis Flashed ¢ Toe) 01 st 1 Foe. t - Retowin Type: __# yerwins —pudpub to the guieen, How punt ©) Woks sn python? a Nou can poss Vosiable, Atrungs, numbers on Other data _ ti as one on move param tuhen ding the pruntc) _ function, Then, these povameteu oe represented as Atiuni 7 thud sepetive stn) Fumtons, To cneate a Angle Butput ny the _tyonifoxmed. me ove concatenated Apoces between them, aw (© scaned ith ok Scammer [Link] - Second Year name= “ALite” Python Programming a 25 pai " Hello, my _name_i ” name." and Lam", age" yeas old” ) = (uutpus : Hello, Ey name in ALCe and lam asyeary ofd # python end" parameter cr pauit () The tnd__keyword 4s used 40 Apetify the content that ws_40_be__psinttd at Ahe end 4 _the _ tXteustion, . the psu) __ function. By defaults it is set 0” In”, uihith leach 1 the ee qf lune por the execution of pint) statement. # Thu tie wilt qutomatitally add anew 4uie before __| the # ert punt Statement. pouintt" GrnTe way _crasses") #—Tha_purit Function tnd _uuith " *#" as det tn the end__ogument peuint CQ 6 wal TON Aa A J ga tvaye" fat __pxint_(" how axe you", “end = "$5") output “GATEWAY CLASS Hero Givys ** BYE how one you $$ [Link] - Second Year Python Programming By default punt 0 sepoxate the _4tem4 pero The optional _seb = _puxameren acts _a__dipjere Arpounton, sent . : — Peant (12, He = Qs sepets') — es print ( ‘but’ . ‘not’> TT see puis ( ‘but’» ‘net? » * (necting asepe'*) prunt (thi, ‘hello’ ) _ pouine(” gotten.” “elses asf e) = suutput a _ Jaraui-2 but * 4 not ** indudin, but not Anduding hu hello grtewoay oss es Flush potameor wr _ python with pyunt()_fundion Tie 1/05 un python. are guneratty buffered» meanurig they. ame used th chunks. This ut Lue _Fluth tome th adit helps wen to _deevtle _jf thu heed _the __Wltten_content to be bufiered on not auth dt Uo set to fale sf ft a ek foes _ Out] WL be WHiHteA as a seguienee of —thoxatrea pre _afteh the other Thus _pstoces4 _| $1. SEE ee ae wsxtte th Chunks aber i Wwstiting one chaiaciey ot a time. Jo understand the Ue * coue ofthe flush eprqument inthe panty func [Link] - Second Year —— Keyword Python Programming fython keywords ane Are predefined and siesenvect __ Word "uA _python that have _specanl _mearvngs._ Keywords ave Used to dlefine the ayntar of * the pate The_keywoo dl tonnot pe Used as fn sd entipier, function» ey “vaiable name, ALL the _keywostlr 1A python ae WHALEN un Jowencass eXCepr Tue Pond Fale, - Rus Jor Keywords an pytion Puthon Keywords Cannot be usec os sdentupi eu, Au_the keyword t_python _Ahoutol be Aowercoue txbtpt THue and Fate impot Keyword pint 6 keyword. kwlist#) Keyword -kwlist ; - Th th pt edefined Vorumble_ef._Keywrard mor that stoves dt the keycoond of python, “Thuis _ it tin be used to dl play “alt the _Keqwora of Jud —__ i by taluing is ; python“ pHowide du sh ~ hut module keyword that alow You_4o tna aba tbe auc Vj 2 of python. ee = ll tes yeu the Functionality. _ _ to _knoly about the sowed wonds on keyvorrea cf thon and fo check whether the value ef & Vartable sti Hueryed word Of Noe 3 : (© scaned ith ok Scammer [Link] - Second Year Python Programming _ $n (Ose ypu ove Unaware of all the key wonds of python jou can _ude this module» to yebreve thud _1nfosmotion, Alo 1+ helps you to _theck quhethet a wond u's a Key word ont not ust Using us __flneions _@n___ has sheet sk a f Thu__function _Aetwina Tue if the parameter panied _is us 2 O python _keywond else netumny False. The —parameren ton be a © strug ona eat a_ATing . at according uy compare MrT Me ie defined "in the Lf ane = Import key wond. cd ="Ine ire “hwo _ paint (8) " Ma Kepuord_sh_ yt 4h_pyth pound C5" 6 Kes th_pyinen ine pau (Us" 4 0 Hen ‘fem a —_ 1, key wond- iskequsorlts pth d CE 44 ee te wn did dh naa Tae hele wu dn_python False (© scaned ith ok Scammer [Link] - Second Year Python Programming TMPORT Tmpont th python is _atmilor_to detnetude headen_ File iC C++,“ Pyihon modules _cOn__get_acteoy tp Code From another moduute Oy impo2tting the He] fundion __ ding fmport. The in port _Sdatelrent 44 the _moed | tpntmon wr of ‘nvoking the Lim post Machinery, but _ vt us not Fhe_onty way impoxt _modiule_ name ee when the import ua wed» jt senncher the medwe invtfaey, dn the Local Acope hy (oLuing Import —-L) punetien, — The_volue _ Hetwaned the function -u__then __ Heflected tn the owtput “of ihe _tinitint code. |__in_the above code modute, mah 14 _imposded sand its —Vavuinbles _can_be _ateesed NE Pomc yt Be tO Wh eh : netwined by —_lmpost 0), pr oa —uthole tan _be _ymmportec shi “own thitial code, darker thon _imponting the _uthole module bom math import pif a © seamed ith one Seamer © seamed ith one Seamer

You might also like