Page 182 - Computer Science Class 11 With Functions
P. 182

Stringonarencomparednfromnleftntonright,nexaminingneachncharacternonenbynone,nuoingntheirnASCIIncodeo,nwhichnarenaloon
        knownnaonASCIInvalueo.nNotenthatnthenvalueonpaooedntonmaxnfunctonnmuotnbencompatblenforncomparioon.n ornexample,n
        annumericnvaluencannotnbencomparednagainotnanotringnvaluenaonohownnbelow:n



                 What value does max(-20, -30, -40) yield?




         >>> max(23, 'hello')
              Traceback (most recent call last):
                File "<pyshell#2>", line 1, in <module>
                  max(23, 'hello')
              TypeError: '>' not supported between instances of 'str' and 'int'
        min()
        Thenmin()nfunctonnreturnonthenomalleotnvaluenfromnthenoequencenofnvalueonprovidednaonthenargument.nThenoyntaxnofn
        thenfunctonnion:

        min(<sequence>) or min(<val1,val2,...,valn>)
         orninotance,nthenfollowingnfunctonncallonprintnminimumnofnthennumericnvalueonandnomalleotnotringnfromnthenvalueon
        providednaontheninput:

         >>> min(2,0,-4,19.0,36,8)
              -4
         >>> min('Arushi','Muskan','Sameer','Ayana')
              'Arushi'
        sum()
        Thensum()nfunctonnreturnonoumnofnallnnumericnvalueoninnthengivenninputnoequence.nOptonalninputnnum2,nwhenn
        provided,nionaddedntonthenoumnofnelementonofnthenoequence.nThenoyntaxnofnthenfunctonnion:

        sum(<sequence [,num2]>)
         orninotance,nthenfollowingnfunctonncalloncomputeonoumnofnallnelementoninnthengivennoequence:

         >>> values = (1, 3, 5, 7)
         >>> sum(values)
              16
         >>> sum(values,5)
              21
         >>> sum((1, 3, 5, 7))
              16
        Notenthatnthenonninvokingnthenfunctonnsum(values,5),nitnnotnonlyncomputeonthenoumnof 1, 3, 5, and 7,
        butnaloonaddo 5 tonthenoumnof 16ntonyield 21.
        divmod()
        Thendivmod()nfunctonntakeontwonnumericnvalueon-integernornfloatngnpointnnumbero,noaynnum1 andnnum2 aoninputn
        fromnthenuoernandnreturnonanpairnofnvalueoncomprioingnquotentnandnremaindernwhennnum1niondividednbynnum2.nThen
        oyntaxnofnthenfunctonnion:

        divmod(num1, num2)
         orninotance,nthenfollowingnfunctononcalloncomputenquotentnandnremaindernforndifferentnpaironofndividendonandndiviooro:n

         >>> divmod(17, 4)
              (4, 1)
         >>> divmod(21.5, 5)
              (4.0, 1.5)
         >>> divmod(-21, 5)



         180   Touchpad Computer Science-XI
   177   178   179   180   181   182   183   184   185   186   187