0% found this document useful (0 votes)
26 views7 pages

Python Fundamentals Cheat Sheet

Uploaded by

moresanket3004
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)
26 views7 pages

Python Fundamentals Cheat Sheet

Uploaded by

moresanket3004
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
1124, 750M sbourblank Python Programming Fundamentals Cheat Sheet Package/Method Description ‘Syntax and Code Example Syntan (Cepaat) Example: esas “Tras if both statement and stern? are “Trae Other, AND returns "False some ety fees Copied - Syn (Govaa) Example Defines blueprint for creating objects nd defining thee atibutes and less Definition nes Scr ine_teet, sane, 26 Example (pareneters): # Function bagy ‘A function’ i reusable lock of code that performs speci tsk or Define Funstion ser af tas when called 1 def groet(eate: print(elio,", rare) (Cepeat) Chocks ftw vale ae ou Syntax: Copia Example (eerie) returns Tue ample 2 aboutblank wr ‘yi24, 7:50 PM. about:blank (Copeat) seta False Syntan: (Ceneat) ample or nan sn range, 10) ‘Afar’ lop repeatedly exceutes lock of code fora specified mumber ni ‘of erations or overs sequence of elements (Us ranger ing et), For Loop capaal) Example 2 2 frat « (apes, “tonane,“ 2 fon rate in fasts 3 pene) ese] apa) Syntax 1. fanctlon_seneargments) Example ‘A funtion eal athe act oF executing the code within the fanetion Function Cal ‘sing the provided arguments, 1 ereteratice") (copeat) Syotae Example (eerie) Greater Than or El Seer Cesk ifthe ale of vane in retro exo vrisble Example 2: (Cea) tune True Greater Thane) Checks ifthe value ofvaviablel i greeter than varie, Syntax: Copia Beample 1:96 returns Tue aboutblank 2 ‘yi24, 7:50 PM. Statement Ieee Hse Statement aboutblank about:blank Hample2: returns False Syntax (ceria) Executes codeblock if the conn is Truc Example 3 pranttie's 9 me aay") (Cepeat) Syotan cage if conaitiont 4s Tre se: apa) Brecutes he fis codeblock i eon! it "Tae otherwise checks condition2, end soon. no conditions Tue’ the ese Block is Example nected. prane("ou got an Al") ease tcore eB eaprimcton est 98.7) PrintYou need to work marr. Bo ocrue = You got a 8. (Ceseat) Executes he fit code block ifthe condition i "Tue otherwite the Sy second bck el (cepa) Example Br Sate Ateuee an aa") ‘yi24, 7:50 PM. Less Tha or Equal Te) ess Than) Loop Contos aboutblank Chocks ifthe vale of varibll ie les than or elo variable? (Chosks ifthe value of vail ees tha variable “break exis the loop prematurely, contin’ skips the ret ofthe cument teration and moves fo the nex eration, about:blank AM Seemeevouine not an adult yet. api) Syntax apa) Example 1 (ceopeat) retune True Peample 2: (Conzat) return Tre Syntax Example 1 (cepa) return Tee 3, Sore passing sone capi) returns True Syntan 1 font code 20 epost BP Paton geatenent apa) ample 1 an ‘yi24, 7:50 PM. Nor Not Eat!) Object Creation on aboutblank ets “Tras if variables ake and vie vers Chocks ftw vas ae not equal (Creates am instanceof a clas (object) using te class constructor Returns “Tru if iter statement or statement (rbot) ae True! (Otherwise, reuns False. 2. for pan in ranges 6) 2 printinn) 1 fariable (Cena) ample Copia returns True ithe variable Fate, unlocked), Syntas (ceria) Example (cna) retuna True returns False Syntax 1. object_nane = Classkane(arganerts) (ceria) Example: 1 person = Personalsce", 25) (Coat) ‘Syntan 1, statnentt |] statement? Copia 57 ‘yi24, 7:50 PM. ranged Retara Statement Tiy-Except Block Tiy-Exoept with Ese Blosk aboutblank Generates a sequence of numbers within a specitid range Return’ isa keyword used to senda valu back fom a function its ‘Tees wo execute the code in the ty block. an exception ofthe specified ype secu, the code the except block i execued Code inthe "ls" los i exosued if no exception ovat inthe ty tock, about:blank Leample yal returns True Syntax 1 eagetston) 2 ciegetstort, stop) EL Gigjtare, San ox (cepa) Example 1 caets) toenrates a sequence of integers fron 00 4 2 Choet2, 25) tganeratee a seqance of imagers trav 230 8, Bo tagets; 18) 2) tgeneracar de sateger rem 4 t0 3 (copeat) Syntax Copia Example: 2 Gof adata, 9): otuen a 6b 2 eee ei, 5) (Conia) Syntax: 2 ty: # cole that mlgnt rate an exception except 2 Exteptiontyoe”# Coot to handle the exception Copia Peample: 5 Mn stating eater 3 eaters“) a Grane Sanenlig input, Please enser 9 valid number.) (cepeat) Syntan 2 ty: # colo ana mlgnt raze an exception except Petre # ib cotarle te see ton Example ‘yi24, 7:50 PM. Tiy-Except with Fall Block exception scouted while Loop Specified condition remains True @® Skills Network (© IBM Corporation, AM rights reserved. aboutblank ‘Code in the “nally’ block always executes, regardless of whether an Awhile loop repeatedly executes a block of code as long about:blank wy run = tn(lngur("Enter 2 rare: °)) except Valueerrar rine(Sinaila Sap. Please enter a vals number”) se Print-You entered", mony (Copa) Syntax 3. Pealiys"e Zeenat alan exoestee (Copied) Exanple etze = gpntrantactxt, °°) Estee cncept fa ehtFounderor SS eunt tie nt fod.) ‘tfeccoset) (Ceonzat) Syntax 1 count = @ ante count ¢ 5: Fedotov) count an a

You might also like