Suggest appropriate functions for the following tasks –(a) To check whether the string contains digits.(b) To find the occurrence a string within another string.(c) To convert the first letter of a string to upper case.(d) To convert all the letters of a string to upper case.(f) To check whether all the letters of the string are in capital letters.(g) to remove all the white spaces from the beginning of a string
Question
Suggest appropriate functions for the following tasks –(a) To check whether the string contains digits.(b) To find the occurrence a string within another string.(c) To convert the first letter of a string to upper case.(d) To convert all the letters of a string to upper case.(f) To check whether all the letters of the string are in capital letters.(g) to remove all the white spaces from the beginning of a string
Solution
(a) To check whether the string contains digits, you can use the isdigit() function. This function returns True if all the characters are digits, otherwise False.
(b) To find the occurrence of a string within another string, you can use the find() function. This function returns the lowest index of the substring (if found). If not found, it returns -1.
(c) To convert the first letter of a string to upper case, you can use the capitalize() function. This function converts the first character of a string to capital (uppercase) letter. If the string has its first character as capital, then it returns the original string.
(d) To convert all the letters of a string to upper case, you can use the upper() function. This function converts all lowercase characters in a string into uppercase characters and returns it.
(f) To check whether all the letters of the string are in capital letters, you can use the isupper() function. This function returns True if all the characters are in uppercase, otherwise False.
(g) To remove all the white spaces from the beginning of a string, you can use the lstrip() function. This function returns a copy of the string with leading whitespaces removed. If no parameter is passed, it removes spaces.
Similar Questions
How would you modify these functions to correctly check if a string has any lowercase letters while effectively traversing the entire string without returning prematurely?
Which method can be used to return a string in upper case letters?
Write a program to check whether a given character is Alphabet or not using if else statement Note: Check for both upper and lower case characters
Which of the following string methods returns the string value converted to uppercase?1 pointindexOf()toUpperCase()concat()length()charAt()equals()
Complete the following code to find lowercase and uppercase letters from a given string using regular expressions. Sample input:WelcometoINDIASample output:[‘W’, ‘I’, ‘N’, ‘D’. ‘I’, ‘A’][‘e’, ‘l’, ‘c’, ‘o’, ‘m’, ‘e’, ‘t’, ‘o’]
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.