String Assignments
String is a Collection of __________
2. Strings are enclosed within _________
Single Quotes (' ')
Double Quotes (" ")
Triple Quotes (''' ''' or """ """)
Any of the Above
3. What is the Positive and negative index number of space in Word - David Joseph:
4. How to get the first character in upper case from the name inputted by the User. For example :
name : 'david Joseph'
Output : D
5. You work in a company and you are given customers number, But many customers filled wrong data, so you need to check if the number given by customer is right or not.
Phone Number should match following Criteria :
Only numbers , spaces are allowed though (so few customers wrote their number with spaces.)
10 character only.
For Example
input : 976 543 2319
Output :
check_number : True
ten_character : True
6. Find the second maximum digit from a number
.
7. You work in a bank, You are tasked to create a pin with the help of their customer name and birthyear .
Input Customer Name : david josh
Input Date Of Birth : 09-12-1997
Output:
pin : David1997
8.You are tasked to swap first and last characters of a string.
For Example:
Input string : 'python'
Output :
'nythop'
9.Take a String from user consisting only alphabets and spaces, and count How many Consonants and Vowels are in the string.
input string : 'This is example'
Output :
Total Alphabets : 13
Total Vowels : 5
Total Consonants : 8
10.Check if a string is palindrome or not. Palindrome is a string that does not change even if you reverse it.
For example:
input string : 'rotator'
Output:
Palindrome : True
input string : 'python'
Output:
Palindrome : False
11.Imagine You run an Institute where all your students are stored in a variable something like this :
students = 'david mark bill sam'
You have a few tasks to do like :
students = 'david mark bill sam'
input :
Enter the name of the student : jeff
david mark bill sam jeff
Find out the name of the company from a URL inputted by the user. Example: url= www.facebook.com Output: facebook
Which of the following is not a valid string method in Python?
a) upper() b) lower() c) title() d) subtract()
Which of the following code snippets will concatenate two strings in Python?
a) string1.append(string2) b) string1.join(string2) c) string1 + string2 d) string1.concat(string2)
Which of the following is the correct way to access the first character of a string in Python?
a) string[1] b) string[0] c) string[2] d) string[-1]
Which of the following code snippets will reverse a string in Python?
a) string.reverse() b) reversed(string) c) string[::-1] d) string.reverse_string()
Which of the following code snippets will return the length of a string in Python?
a) len(string) b) string.length() c) string.len() d) length(string)
Which of the following code snippets will replace all occurrences of a substring in a string in Python?
a) string.replace(old, new) b) string.sub(old, new) c) string.replace_substring(old, new) d) string.substitute(old, new)
Which of the following code snippets will split a string into a list of substrings based on a delimiter in Python?
a) string.split(delimiter) b) string.divide(delimiter) c) string.cut(delimiter) d) string.separate(delimiter)
Which of the following code snippets will convert a string to all lowercase letters in Python?
a) string.lowercase() b) string.to_lower() c) string.lower() d) string.convert_to_lower()
Which of the following code snippets will remove leading and trailing whitespace from a string in Python?
a) string.strip() b) string.trim() c) string.remove_whitespace() d) string.trim_whitespace()
Which of the following code snippets will check if a string starts with a specific substring in Python?
a) string.check_start(substring) b) string.begins_with(substring) c) string.startswith(substring) d) string.starts(substring)
Which of the following code snippets will split a string into a list of characters in Python?
a) string.split() b) string.chars() c) list(string) d) string.list()
Which of the following code snippets will check if a substring exists in a string in Python?
a) string.exists(substring) b) string.contains(substring) c) substring in string d) string.sub(substring)
Which of the following code snippets will count the number of occurrences of a substring in a string in Python?
a) string.count(substring) b) string.occurrences(substring) c) string.find(substring) d) string.index(substring)
Which of the following code snippets will check if all characters in a string are alphanumeric in Python?
a) string.is_alpha_num() b) string.is_alphanumeric() c) string.isalpha() and string.isdigit() d) string.isalnum()
Which of the following code snippets will convert a string to a list of words in Python?
a) string.split() b) string.words() c) list(string) d) string.list_words()
Which of the following code snippets will check if a string ends with a specific substring in Python?
a) string.end(substring) b) string.check_end(substring) c) string.endswith(substring) d) string.ends(substring)
Which of the following code snippets will return the index of the first occurrence of a substring in a string in Python?
a) string.find(substring) b) string.index(substring) c) string.first(substring) d) string.search(substring) e) Both a and b
Which of the following code snippets will check if all characters in a string are in lowercase in Python?
a) string.islower() b) string.is_lowercase() c) string.islowercase() d) string.is_lower_case()
Which of the following code snippets will remove all occurrences of a character in a string in Python?
a) string.remove(char) b) string.delete(char) c) string.replace(char, '') d) string.sub(char, '')
Which of the following code snippets will check if all characters in a string are in uppercase in Python?
a) string.is_uppercase() b) string.isupper() c) string.is_upper() d) string.is_upper_case()
Last updated