Page 316 - AI Ver 1.0 Class 9
P. 316

To  display['C',  'A',  'T']  from  the  word[3:6]         ['C', 'A', 'T']
               above list
                                                or
                                                word[-6:-3]

                                                or

                                                word[3:-3]
                                                or

                                                word[-6:-3]
               To  display  ['O',  'I',  'T']  from  the  word[7:4:-1]    ['O', 'I', 'T']
               above list
                                                or
                                                word[-2:-5:-1]

                                                or

                                                word[7:-5:-1]
                                                or

                                                word[-2:4:-1]
               To display the list in reverse order word[::-1]            ['N', 'O', 'I', 'T', 'A', 'C', 'U', 'D', 'E']





                      Task


             If word = ['E', 'D', 'U', 'C', 'A', 'T', 'I', 'O', 'N']

             What will be the output of the following instructions:
             ●  print(word[:1:-2])
             ●  print(word[-1:])

             ●  print(word[:-1])


        Adding New Elements to a List

        There  are  three  different  functions  used  to  add  elements  in  an  existing  list  which  are  append( ),
        extend( ) and insert( ). Let us learn about them in detail.

        The append( ) Function

        The append( ) Function appends a single element with the given value(any datatype) at the end of the list.
        We use this function in a loop for adding multiple elements. With the single append( ) function, the length
        of the list will increase by 1. Syntax of the append( ) function is:
           list.append(item)








                  314   Touchpad Artificial Intelligence-IX
   311   312   313   314   315   316   317   318   319   320   321