Page 180 - Computer Science Class 11 With Functions
P. 180
Anfunctonnionanoub-programnthatnmanipulateondatanreceivednaonanninputntonoolvenanproblemnornoub-problemnofnancomplexn
problemnandnoftennreturnononenornmorenreoulto.nOncenanfunctonnhaonbeenndefined,nitnmaynbencallednoeveralntmeonfromn
differentnpartonofnthenprogram.nSuboequently,nthenfunctononarenintegratedntonoolventhencomplexnproblem.
The programming methodology that focuses on organising a computer program into smaller manageable
sub-programs or modules is called modular programming.
8.1 Built-in functions
Pythonnprovideonanlargennumbernofnpre-definednbuilt-innfunctononouchnaoninput(),nprint(), and abs().n
Somencommonlynuoedntypeonofnbuilt-innfunctononarenrelatedntoninput-output,ndatantypenconveroion,nandnmathematcaln
operatono.nAnfunctonnioninvokednuoingnthenfuncton'onnamenfollowednbynthenoequencenofnargumenton(oeparatednbyn
commao)nwithinnanpairnofnmatchingnparentheoeo.nThenfunctonnargumentonoervenaoninputontonthenfunctonnfornperformingn
itoncomputatono,naonilluotratedninnthenexampleo.
8.1.1 Commonly used Built-in Functions
print()
Aonthencomputernocreennionthendefaultndevicenforndioplayingnthenreoulto,nthenoutputnproducednonninvokingnthenprint()n
functonniondioplayednonnthenocreen.
>>> print('Hello')
Hello
Innthenabovenexample,n'Hello' ionthenargumentnpaooedntonthenfunctonnprint().nThenprint()nfunctonnmaynben
invokednwithnannarbitrarynnumbernofnargumento.n ornexample,nthenfollowingnfunctonncallnmakeonuoenofntwonargumento:
>>> print('Hello!', 'How are you?')
Hello! How are you?
Next,nwenmakenuoenofnprint() functonnforndioplayingnthenvaluenofnannarithmetcnexpreooion,
>>> print(2+14)
16
Innthenabovenexample,nthenprint() functonnacceptonthenargumentnn2+14, evaluateonit,nandnprintonthenreoultnofn
thenevaluatonn(16)nonnthenocreen.nMorengenerally,nwenmayninvokenthenprint() functon withnoeveralnargumenton
oeparatednbyncommao.n orninotance,nthenfollowingnfunctonncallndioplayonthenotringn'Sum total of 4 and 5 is'n
followednbynanopacenfollowednbynthenreoultnofnexpreooionn4+5:n
>>> print('Sum of 4 and 5 is',4+5)
Sum of 4 and 5 is 9
What will be displayed on executing the following statements?
print('4*5', 4*5)
input()
Theninput()nfunctonnreadonthentextnenterednbynanuoernuntlnannewlinenionencountered.nSuppooe,nwenwiohntontaken
thennamenofnanprogrammingnlanguagenaontheninputnfromnthenuoer.n ornthionpurpooe,nthenfunctonninputnmaynbeninvokedn
aonfollowo:
>>> language = input()
Python
>>> language
'Python'
178 Touchpad Computer Science-XI

