Python String Practice Questions


  1. Find the output of the code :

    s = "Python is fun"
    x = s.split( )
    s_new = "-".join( [ x[0].upper( ), x[1], x[2].capitalize( ) ] )
    print(s_new)
    
  2. PYTHON-is-Fun

  3. Consider the statements given below and then choose the correct output from the given options :

    pride="#G20 Presidency"
    print(pride[-2:2:-2])
    
  4. ceieP0

  5. Predict the output of the Python code given below :

    Text1="IND-23"
    Text2=" "
    I=0
    while I<len(Text1):
          if Text1[I]>="0" and Text1[I]<="9":
                Val = int(Text1[I])
                Val = Val + 1
                Text2 = Text2 + str(Val)
          elif Text1[I]>="A" and Text1[I]<="Z":
                Text2=Text2 + (Text1[I+1])
          else:
                Text2=Text2 + "*"
          I+=1
    print(Text2)
    
  6. ND-*34