Here are some basic and advance questions on Python strings
Basic Questions on string
Create one multi line string and find out its length.
Take input text and print by making first car in upper case.
Keep your name at center and fill both sides by using stars ( * ) of half of your name's length.
Change all chars present in this string to lower case "dDcßeF"
What is the difference between casefold() and lower() methods. (Hint : Use above string )
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
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
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.
Find out the length of your userid in your email address. If your email address is email@example.com then script should return 4.
Search for P inside string Welcome to Python and print the position.
Check if input userid is consist of only char and number.
Check if input userid consist of only chars
Create strings with values '2.4' and check the output by using isdecimal() string method. Check the ouput by using string '123'
How to check if the string can be used as a variable or a name of the function?
Hint: Use is identifier()
How to check if all words start with upper case chars or not ?
How to check if all chars are in lower case or not ? Give examples
How to check if all chars are in upper case or not ? Give examples.
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.
Use the string my_str = '2²' , then check isdigit() and isdecimal() difference.
Take one input string and add * between each char.
Hint : use join()
Use any iterable objects and add @ between each element and print the output
Use the string Welcome to Python , break it into three parts by using to as delimiter.
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
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
Find out the frequency of occurance of chars in a string
Advance Questions on String
Display one input string after adding x zeros, where x is equal to half of the length of the string
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
What is the difference between rfind() and rindex()
Input string is 'Welcome to plus2net.com'. Replace the .com with .net
Find out the number of occurrence ( frequency ) of each chars in a string
Create a string by using first two chars , last two chars and middle two ( or three based on centre ) chars of a input string.
From one input string, char with highest occurrence ( frequency ) should be replaced by its number of occurrence
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.
Arrange one input string in such a way that Upper case letters should come first
Change to upper case all the chars at even index position
Collect the following details . Title , description, keywords , body , H1, Details and then create one html page and save as my_name.html
Insert second string at the centre of the first string
Create Caesar encryption of an input string
Convert first n chars to upper case
Find out the first repeated char in a string
Change to upper case char for all first and last char of words present inside a string
Count number of special chars, upper case , lower case and numbers present in a string
Collect the integer part from the string. Input = I joined college at 18 years of age Output = 18