0% found this document useful (0 votes)
40 views

python m 1, 2.pdf

Simple Portable Scalable: Provides improved structure for supporting large programs. Integrated Expressive Language 1.3 Python Interpreter: Names of some Python interpretars aru

Uploaded by

myindia359
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)
40 views

python m 1, 2.pdf

Simple Portable Scalable: Provides improved structure for supporting large programs. Integrated Expressive Language 1.3 Python Interpreter: Names of some Python interpretars aru

Uploaded by

myindia359
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
You are on page 1/ 12
CHAPTER-1 INTRODUTION TO PYTIPON 11 introduction: * cral-purpase C&yject Clriented Proprecming legume * Be © Developed in late 180 by Galde van Rossum at Necienal Research lnscimes for Mathematics and Compurer Science inthe Netherlands. & Wis derived from poegsumming lasguages such as ABC. Modula 3, small talk, Algel- ok, fis Open Source Seripring lang [is Case-sensittve Innguage (Difference hetween uppercase and lowercase letters) & Oneof rhe official langunges 2: Gangle. me 1.2 Characteristics of Pythons wf Latexpected: Ph sole Interaeti an sures code is compiled to byte code as a vpye file, axel this byte ibe Hikerppeted by the Leiterpecter Iriented Poogramning Language vw ¥ ¥ imple ¥ ¥ c: Provides amproved shuclure fir seppurling large poogsams. “ e Expressive Language 1.4 Pythen Interpreters Names af sume Python interpeclers are: * Python ILE * The Pyther Bundle * pellll + Sublime Text ote. There are tae mades te use the pathan interpreter i. Inversctive Made ii, Serpl Mede Interactive Mode: Witkoul passin interpreter, direc 1 Serlpr Mates amd ue Ube ante peeter, vo wb the Write I directory is Co a 2.1 Puthow Character Set: Head a sctol valid characte that a himgange recagitiee, Letters: AF ar el Special 3y ovals: ‘Whitespace 2LTOKENS CHAPTER-2 Pyros BUNDIAMIEN PALS Tolcen: Smallest indivicue! unit in a program is koown 2s taken. Vere are five types ul taki in pytlson: 1. Keyward lide iier . Literal _ Operatars Prntctoanes Sf ke ta Keyword: Reserved words in the brary ata language, Chere ane 33 keywords in pyllen. False class Cimalls is nolum = Drak Nome canrinue | far lambsia ry excest Tne ier Foe nonleent while jin and del global nal with raise | as “ene i ar | yiekd | asset! lee inept, pranas AMllihe keywords av in lowercase except 02 key woods (Truc, Fals. Name}, 2. Idemiifier: The name given by the weer bo Ube entities like variable man Function-nare ete. Aloe fo lea es # Tecan be 2 cambinarion fletters in bewercese (a er} ar uppercase {4 to F) ar digils (ia 9) or aa underscore. © Ieweceat star, wath w digit, = keywards commol be sescal as an adonlilicr. = We cannat use special aymbels lilbe °, (2), 4, 8, ‘4, + ete. in identifier. © _ (unelerscore ens be used ie Wenticier, = Commas or blank soaces are nee allowed within an identifier. 1. Literal: Literals are the constant value. Literals can he defined as a data that & given ino variohle ew cometon AQ Numeric literabs: survctiv Lilerals cov imental, Fg. 5, 63, ij R, String Hterats String literals a he carmed by enclosing a text in 2 well as deuble pntes for a String, quotes, We can use batt: single as Eg: “Ames” 12345" Eseaqe sequence charactors: Riackslash 7) Sirgghe quete P[Troalse quone a | ASCII Bell be | Brckepace | ASOT Pormfesd 0, Benleam Hecral: cal’ the: tens val Troe ce False, Uh. Sprowkal Werle: sthen contains ane special literal ie. Name. Nome is usad to spc vtu thal Sick thal is not enced Wis also vecd for cmd of lists in Python, E Atcral Collections: Collections such as tuples. lists and Dictianacy ane used in Pte, 4. Operators: Aan operator performs the apemilion en operimds ere are two Types al operators in pylhun acconding to number of opctameds: A. Coury Opervtar D. Binary Opersior A. Unury Operate: Pecforms the eseration on one operand, Example: Lneiry ils - Unary sinus Dirwise complement nat Lagizal negarien BL inary Chperntor Perfonms op jam an twa cmperncds, 5. Separator or puncriscae SathT bE SLs and Eee Portia, Acreal number inegporcnt farm has baw paris: & mantissa ® exponent Manisa: 1 const be citieran utieger ara proper real orslal, Eecpoment It mat hean integer Represented hy & letter Fare falleseeee by Valld Exponent form Invalid Exponent form 133EUS 2.3K (Mo digit specified lise expunentl V23E07 4.34P4.3 (Paponent canner have finctional part) .25E08 banrus 25,455EU3 (Ne vocumaalivmed) 123513 i330End Ise Ina ha ee Est tet LD i Cp atle AL Mocks and Iedeotation B. Stuements: C. Egpresssions 1, Com mens AL Bloeks and Indentation: © [then provides no Graces bo indacale blocks ef code: fon class amd Cumetion deli flow comtral. * Maxienum line leagth should be maxomum 74 characters, « Blocks of code ove denoted by line i titenents within the block The number af spzces in rive indentation is variable, hur al cemuest festa hentbacul ne: artes, for exanaphe True: printf" True” whe: rimlt"“Fialssc’"} H.Staterments AlLine which hss he nestrocions or cxpressions. 1. Evpressions: Alen combination of sembols and values that produce a result. Generally it penduces av DB, Comments: © program understandable and readable, AM characiers after the @ amd uo te the cal al the Is ane Hol execLied, Comments explains peogrinm ed omke physical line are part af the camment and the Python imerpreter iqees them. There ane bya types of cammecnis in psthan: 1 Siege Lite ent ii, Multi-line comment Single line ennament; This type af comments start ina line seed whee a line ends, ot is automatically ends, Single line comment staris with # synbal. Example: iseb: i Relalioaal operates compare iva wanes ab Multi-Ling coment: Meu queted | 7 "oar 7 coulti-line comments may duestring Frample: mirictd cam Bo osritten im amore than ane lines, Triple be usa in python [Mis alsu known as © This program will calvalate tke average af 10 values, Fi aed divide the sen by smamber of values Vic! the sun of 10 values A ThLs program shows &propram's comcanents EDeFindtios of function seevout) Follee a SOF Soweto): ee nh a Print (Time to-say Gord bye tity APOSn preg ran-code fallow nce ae is. “ o be aa print (a+ay weaken maar bt? af best blocks coe BPUE (Walp of wan more than 2S initially. “) = = f commew beplntng: terineiad Go. glee 1 fia the oa Rt “sg pPint (Vale oF at wae IS lews ntdaddy") 9! Seevoet) fcallieg show defined furcticn Sewyoet Multiple Starements om a § gle Bane The semicokon (; | allows mulciple slurs a new evde bh meals ott the ainghe Line given that mcither salen i location thal refers ton wal during, program exeeutien ¢ nnd wiicee value can be used and processed Variables is python do co! have fined localicns. The location they refer to changes every time Cicie values change. Creating a variable: varah ed the moenent yoo first assigys a-vahae to it, Example neva yo hello” Wariabice du met col fa be dcclorod wilh any pocticular Lype aun can even change type aller tis known as dynamic Typing. iype int is now af'ey primes) Rules tor Prtion varloteles: + A-variahle came must stet witha letter or the anderoare character characters and underscore (Az, 0.8. + Variable names ace case-sensitive (age. Age and AGE are theee different variables} Python alloves assign asingle value bo nalliple variables Example: xy -z75 os arom ‘You cant lst assign vllipe risks (Rar example keyed 2 python” Ais aceinned tow, § it assiqned say and string “pachon” assigrad tr. variable 2 respectively molt yl Ay pein.) Now the result Cr) lvalug ond Rvalic: An expression bas two values. Lvaloe xd Bvahue. Lealue: the LIS port of thie Balinese RNS pact off the expression Python first evaliaites the RAS expressian aid then assigns te LHS sium Example: mars, 1,7 aon po pel qed pr pq Mew the result will he: & a iz Note: Expressions separmed with cocamus arg evaluated from efi to right and sssigned in same oder. & [0 you vant to Kin the ype of variah SUNT Le ty pet) Tintieliens Syntax: (variahle-came} Taample: xh expel) re rian at thee pal eau Use Un You can delew single or mulliple vasiables by using del stateccnl. Example: dels uel ye Ll I es Inpani j miethod is use Fron the user Example: = yall uni Helle, "+21 alvenyd returns a valle of siring lype. a9 - To convert one data type int Miser kal ype Casting in python is therelime dime ussng eonsteutor lunelioess: + Intt )- constructs am integer manber from. an integer literal, a Moet literal oo string lasted. a= intl) Fa will be 1 ap will be 2 zwallbe 3 « Boalt} -consizucis a feat number from an in wcral, a Hat literal ora string literal xo Dol) Ax willbe Lo ALS) Ay will he 28 3°) #a will be 3 wo font "4.2" ) oo will he 4.2 + str} constracts a string from a wide vesiety af data types, includin strings. integer jivcrals and ual liberals. acstn sD" a will be aL" yrs) ty will be 2 xo sri 3.0) Fe will Lie Reading a number trom a user: a int Cinputt aqgacr camibz"}} Se tgs po Sibi Sy-nta Peinw ober sep-Secpuraber elring , ond-“aned-siring*|

You might also like