Python String questions

Here are some basic and advance questions on Python strings

Basic Questions on string

  1. Create one multi line string and find out its length.
  2. Take input text and print by making first car in upper case.
  3. Keep your name at center and fill both sides by using stars ( * ) of half of your name's length.
  4. Change all chars present in this string to lower case "dDcßeF"
  5. What is the difference between casefold() and lower() methods.
    (Hint : Use above string )
  6. What are the outputs of below code ?

    my_str="Welcome to Python"
    print(my_str.count('co')) # Output is
    print(my_str.count('co',4)) # Output is
    print(my_str.count('co',4,18)) # Output is
    print(my_str.count('o',4,9)) # Output is
    print(my_str.count('o',4,10)) # Output is
  7. Print the outputs of below code ?

    my_str="Welcome to google.com"
    print(my_str.endswith('com')) # Output is
    print(my_str.endswith('com',4,6)) # Output is
    print(my_str.endswith('com',3,6)) # Output is
    print(my_str.endswith('go',11,13)) # Output is
    print(my_str.endswith('go',11,12)) # Output is
  8. Take your email address, check that the char @ and . ( dot ) both are present and return the position as they appear of them. If they are not there then print that this is not a valid email address.
  9. Find out the length of your userid in your email address. If your email address is abcd@gmail.com then script should return 4.
  10. Search for P inside string Welcome to Python and print the position.
  11. Check if input userid is consist of only char and number.
  12. Check if input userid consist of only chars
  13. Create strings with values '2.4' and check the output by using isdecimal() string method. Check the output by using string '123'
  14. How to check if the string can be used as a variable or a name of the function?

  15. Hint: Use is identifier()
  16. How to check if all words start with upper case chars or not ?
  17. How to check if all chars are in lower case or not ? Give examples
  18. How to check if all chars are in upper case or not ? Give examples.
  19. Search Google for translate 1234 to chinese, use the result to create a string and then use the isnumeric(), isdigit()and isdecimal() methods to check the output.
  20. Use the string my_str = '2²' , then check isdigit() and isdecimal() difference.
  21. Take one input string and add * between each char.
    Hint : use join()
  22. Use any iterable objects and add @ between each element and print the output
  23. Use the string Welcome to Python , break it into three parts by using to as delimiter.
  24. Create a string with data : Welcome To Python

    Change all lower case letters to upper case letters and vice versa
    Change all to lower case letters
    Change all to upper case letter
  25. Remove .com from the domain name and print the balance string. Example: google.com will return google. From your email address separate userid and domain part
  26. Find out the frequency of occurrence of chars in a string

Advance Questions on String

  1. Display one input string after adding x zeros, where x is equal to half of the length of the string
  2. Read one html page ( use one sample page ) and display the content written inside different tags like <Title>, <Description>, <keyword>, <body> etc . ( View source of any web page will show you different tags )
    You can use sample html page here
  3. What is the difference between rfind() and rindex()
  4. Input string is 'Welcome to plus2net.com'. Replace the .com with .net
  5. Find out the number of occurrence ( frequency ) of each chars in a string
  6. Create a string by using first two chars , last two chars and middle two ( or three based on center ) chars of a input string.
  7. From one input string, char with highest occurrence ( frequency ) should be replaced by its number of occurrence
  8. Take one input string and generate error message if any special char including space is present. Under score is allowed. Add extension of .com to this string and display.
  9. Arrange one input string in such a way that Upper case letters should come first
  10. Change to upper case all the chars at even index position
  11. Collect the following details . Title , description, keywords , body , H1, Details and then create one html page and save as my_name.html
  12. Insert second string at the center of the first string
  13. Create Caesar encryption of an input string
  14. Convert first n chars to upper case
  15. Find out the first repeated char in a string
  16. Change to upper case char for all first and last char of words present inside a string
  17. Count number of special chars, upper case , lower case and numbers present in a string
  18. Collect the integer part from the string.
    Input = I joined college at 18 years of age
    Output = 18
    str='I joined college at 18 years of age'
    for s in str.split():
       if s.isdigit():
          print(s)
  19. Reverse a string ( Solution : Reverse a string )
String
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer