Page 523 - Computer Science V2.0 Class 11
P. 523

Program 32: Consider the following strings:

                     code1 = 'Stay Safe'

                     code2 = 'stay alert and stay safe'
                     code3 = 'STAY AWARE'
                     code4 = '999999999'
                     code5 = 'Call@999'
                     code6 = 'Call999'
                     code7 = '  '

                     code8 = '  Be ethical   '
                     code9 = 'safetyfirst'
                 For each of the commands given in the second column of the table given below, write the output in the third column
                 that will be produced on the execution of the statements (in the second column) by Python interpreter.


                      Sr. No.                        Command                                      Output
                         1    code1.count('a')                                         2
                         2    code2.count('stay')                                      2
                         3    code3.count('a')                                         0
                         4    code1.lower()                                            'stay safe'
                         5    code3.lower()                                            'stay aware'

                         6    code2.upper()                                            'STAY ALERT AND STAY SAFE'
                         7    code2.title()                                            'Stay Alert And Stay Safe'
                         8    code2.capitalize()                                       'Stay alert and stay safe'
                         9    code8.strip()                                            'Be ethical'
                       10     code8.lstrip()                                           'Be ethical'

                       11     code8.rstrip()                                           'Be ethical'
                       12     code1.isupper()                                          False
                       13     code3.isupper()                                          True
                       14     code1.islower()                                          False
                       15     code2.islower()                                          True
                       16     code1.isalpha()                                          False
                       17     code9.isalpha()                                          True
                       18     code4.isdigit()                                          True

                       19     code5.isdigit()                                          False
                       20     code1.isalnum()                                          False
                       21     code4.isalnum()                                          True
                       22     code5.isalnum()                                          False
                       23     code6.isalnum()                                          True

                       24     code1.isspace()                                          False
                       25     code7.isspace()                                          True
                       26     code1.startswith('stay')                                 False
                       27     code2.startswith('stay')                                 True


                                                                                                           Practical  509
   518   519   520   521   522   523   524   525   526   527   528