Python String Board Questions


  1. Write a Python statement for each of the following tasks using built-in functions/methods only :
    To display the number of occurrences of the substring "is" in a string named message. [1 MARK] [2024]

    For example
    if the string message contains "This is his book",

    then the output will be 3.
  2. print(message.count("is"))
    
    OR
    
    message.count("is")
    
    OR
    
    Any other correct variation of the code
    

  3. Identify the statement from the following which will raise an error : [1 MARK] [2024]

    (a) print("A"*3)
    (b) print(5*3)
    (c) print("15"+3)
    (d) print("15"+"13")
  4. (c) print("15"+3)

  5. Consider the statements given below and then choose the correct output from the given options : [1 MARK] [2024]

    myStr="MISSISSIPPI"
    print(myStr[ : 4] + "#" + myStr[-5 : ])

    (a) MISSI#SIPPI
    (b) MISS#SIPPI
    (c) MISS#IPPIS
    (d) MISSI#IPPIS
  6. b) MISS#SIPPI

  7. Select the correct output of the following code : [1 MARK] [2024]

    event="G20 Presidency@2023"
    L=event.split(' ')
    print(L[::-2])

    (a) 'G20'
    (b) ['Presidency@2023']
    (c) ['G20']
    (d) 'Presidency@2023'
  8. (b) ['Presidency@2023']

  9. Write the output on execution of the following Python code : [3 MARKS] [2024]

    S="Racecar Car Radar"
    L=S.split()
    for W in L:
        x=W.upper()
        if x==x[::-1] :
            for I in x :
                print(I, end="*")
        else:
            for I in W :
                print(I,end="#")
        print()
    
  10. R*A*C*E*C*A*R*
    C#a#r#
    R*A*D*A*R*

  11. Select the correct output of the code : [1 MARK] [2023]

    S= "Amrit Mahotsav @ 75"
    A= S.partition(" ")
    print(a)

    a) ('Amrit Mahotsav', '@', '75')
    b) ['Amrit', 'Mahotsav', '@', '75']
    c) ('Amrit', 'Mahotsav @ 75')
    d) ('Amrit', ' ', 'Mahotsav @ 75')
    
  12. d) ('Amrit', '', 'Mahotsav @ 75')
    
    or
    
    Error in code OR no correct option
    
    Note:
    print(A) is wrongly typed as print(a)