91 solutions available
Question 1The string indexes begin 0 onwards.
Question 2For strings, + operator performs concatenation.
Question 3For strings, * operator performs replication.
Question 4The in and not in are membership operators for strings (in, not in).
Question 5The ord() returns the ASCII value of a given character.
Question 6If a string contains letters and digits, function isalnum() will return true.
Question 7'ab'.isalpha() will return value as True.
Question 8To get each word's first letter capitalized, title() function is used.
Question 9Function index() raises an exception if the substring is not found.
Question 10Function split() divides a line of text into individual words.
Question 1Negative index -1 belongs to .......... of string.first characterlast character ✓second last charactersecond character
Question 2Which of the following is/are not legal string operators?in+*/ ✓
Question 3Which of the following functions will return the total number of characters in a string?count()index()len() ✓all of these
Question 4Which of the following functions will return the last three characters of a string s?s[3:]s[:3]s[-3:] ✓s[:-3]
Question 5Which of the following functions will return the first three characters of a string s?s[3:]s[:3] ✓s[-3:]s[:-3]
Question 6Which of the following functions will return the string in all caps?upper() ✓toupper()isupper()to-upper()
Question 7Which of the following functions will return the string with every 'P' replaced with a 'z'?find()index()replace() ✓split()
Question 8Which of the following functions will return a list containing all words of the string?find()index()partition()split() ✓
Question 9Which of the following functions will always return a tuple of 3 elements?find()index()partition() ✓split()
Question 10What is the output of the following code?str1 = "Mission 999" str2 = "999" print(str1.isdigit(),str2.isdigit())False True ✓False FalseTrue...
Question 11Choose the correct function to get the ASCII code of a character.char('char')ord('char') ✓ascii('char')All of these
Question 12Which method should I use to convert String "Python programming is fun" to "Python Programming Is Fun" ?capitalize()title()...
Question 13Guess the correct output of the following String operations.str1 = 'Wah' print(str1*2)WahWah ✓TypeError: unsupported operand type(s) for *...
Question 14What is the output of the following string operation?str = "My roll no. is 12" print(str.isalnum())TrueFalse ✓ErrorNo output
Question 15Select the correct output of the following String operations.str1 = 'Waha' print(str1[:3] + 'Bhyi' + str1[-3:])Wah Bhyi WahWahBhyiaha...
Question 16Select the correct output of the following String operations.str = "my name is Anu John" print(str.capitalize())'My name is anu john'...
Question 17Choose the correct function to get the character from ASCII number.ascii(number)char(number)chr(number) ✓all of these
Question 18s = ' '(single space). Then s.isalnum() will return.TrueFalse ✓Errornothing
Question 19Which of the following functions removes all leading and trailing spaces from a string?lstrip()rstrip()strip() ✓all of these
Question 20Which of the following functions will raise an error if the given substring is not found in the string?find()index() ✓replace()all of these
Question 1Strings have both positive and negative indexes.True
Question 2Python does not support a character type; a single character is treated as strings of length one.True
Question 3Strings are immutable in Python, which means a string cannot be modified.True
Question 4Like '+', all other arithmetic operators are also supported by strings.False
Question 5Functions capitalize() and title() return the same result.False
Question 6Functions partition() and split() work identically.False
Question 7The find() and index() are similar functions.True
Question 8The find() does not raise an exception if the substring is not found.True
Question 9The partition() function's result is always a 3-element tuple.True
Question 10The split() returns always a 3-element list.False
Question 1Write a Python script that traverses through an input string and prints its characters in different lines — two characters per...
Question 2Out of the following operators, which ones can be used with strings in Python?=, -, *, /, //, %, >, <>, in, not in, <=AnswerThe...
Question 3What is the result of following statement, if the input is 'Fun'?print(input("...") + "trial" + "Ooty" * 3)AnswerThe result of the...
Question 4Which of the following is not a Python legal string operation?(a) 'abc' + 'abc'(b) 'abc' * 3(c) 'abc' + .3(d) 'abc.lower()Answer'abc' + .3...
Question 5Can you say strings are character lists? Why? Why not?AnswerStrings are sequence of characters where each character has a unique index....
Question 6Given a string S = "CARPE DIEM". If n is length/2 (length is the length of the given string), then what would following return?(a) S[:...
Question 7From the string S = "CARPE DIEM", which ranges return "DIE" and "CAR"?AnswerS[6:9] returns DIES[:3] returns CAR
Question 8What happens when from a string slice you skip the start and/or end values of the slice?AnswerIf start value is skipped, it is assumed as 0...
Question 9What would the following expressions return?"Hello World".upper( ).lower( )"Hello World".lower( ).upper( )"Hello World".find("Wor", 1,...
Question 10Which functions would you choose to use to remove leading and trailing white spaces from a given string?Answerlstrip() removes leading...
Question 11Try to find out if for any case, the string functions isalnum( ) and isalpha( ) return the same resultAnswerisalnum( ) and isalpha( )...
Question 12Suggest appropriate functions for the following tasks:To check whether the string contains digitsTo find for the occurrence a string...
Question 13In a string slice, the start and end values can be beyond limits. Why?AnswerString slicing always returns a subsequence and empty...
Question 14Can you specify an out of bound index when accessing a single character from a string? Why?AnswerWe cannot specify an out of bound index...
Question 15Can you add two strings? What effect does ' + ' have on strings?AnswerYes two strings can be added using the '+' operator. '+' operator...
Question 1aWhat is the result of the following expression?print(""" 1 2 3 """)Answer 1 2 3
Question 1bWhat is the result of the following expression?text = "Test.\nNext line." print (text)AnswerTest. Next line.
Question 1cWhat is the result of the following expression?print ('One', ' Two ' * 2) print ('One ' + 'Two' * 2) print (len('10123456789'))AnswerOne...
Question 1dWhat is the result of the following expression?s = '0123456789' print(s[3], ", ", s[0 : 3], " - ", s[2 : 5]) print(s[:3], " - ", s[3:], ",...
Question 1eWhat is the result of the following expression?s ='987654321' print (s[-1], s[-3]) print (s[-3:], s[:-3]) print (s[-100:-3],...
Question 2aWhat will be the output produced by following code fragments?y = str(123) x = "hello" * 3 print (x, y) x = "hello" + "world" y = len(x)...
Question 2bWhat will be the output produced by following code fragments?x = "hello" + \ "to Python" + \ "world" for char in x : y = char...
Question 2cWhat will be the output produced by following code fragments?x = "hello world" print (x[:2], x[:-2], x[-2:]) print (x[6], x[2:4]) print...
Question 3Carefully go through the code given below and answer the questions based on it :theStr = " This is a test " inputStr = input("...
Question 4Carefully go through the code given below and answer the questions based on it :testStr = "abcdefghi" inputStr = input...
Question 5Carefully go through the code given below and answer the questions based on it :inputStr = input(" Give me a string:") biglnt = 0 littlelnt...
Question 6Carefully go through the code given below and answer the questions based on it :in1Str = input(" Enter string of digits: ") in2Str =...
Question 7aFind the output if the input string is 'Test'.S = input("Enter String :") RS = " " for ch in S : RS = ch + RS print(S +...
Question 7bFind the output if the input string is 'Test'.S = input("Enter String :") RS = " " for ch in S : RS = ch + 2 + RS print(S +...
Question 8aFind the errors. Find the line numbers causing errors.S = "PURA VIDA"print(S[9] + S[9 : 15])AnswerThe error is in line 2. Length of string...
Question 8bFind the errors. Find the line numbers causing errors.S = "PURA VIDA"S1 = S[: 10] +S[10 :]S2 = S[10] + S[-10]AnswerThe error is in line 3....
Question 8cFind the errors. Find the line numbers causing errors.S = "PURA VIDA"S1 = S * 2S2 = S1[-19] + S1[-20]S3 = S1[-19 :]AnswerThe error is in...
Question 8dFind the errors. Find the line numbers causing errors.S = "PURA VIDA"S1 = S[: 5]S2 = S[5 :]S3 = S1 * S2S4 = S2 + '3'S5 = S1 + 3AnswerThe...
Question 9What is the output produced?(i) >>> "whenever" .find("never")(ii) >>> "whenever" .find("what")Answer(i) 3The starting...
Question 10What is the output produced?(i) >>> "-".join(['123','365','1319'])(ii) >>> " ".join(['Python', 'is', 'fun'])Answer(i)...
Question 11Given a string S, write expressions to printfirst five characters of SNinth character of Sreversed Salternate characters from reversed...
Question 1Write a program to count the number of times a character occurs in the given string.Solutionstr = input("Enter the string: ") ch =...
Question 2Write a program which replaces all vowels in the string with '*'.Solutionstr = input("Enter the string: ") newStr = "" for ch in str :...
Question 3Write a program which reverses a string and stores the reversed string in a new string.Solutionstr = input("Enter the string: ") newStr =...
Question 4Write a program that prompts for a phone number of 10 digits and two dashes, with dashes after the area code and the next three numbers....
Question 5Write a program that should do the following :prompt the user for a stringextract all the digits from the stringIf there are digits:sum the...
Question 6Write a program that should prompt the user to type some sentence(s) followed by "enter". It should then print the original sentence(s) and...
Question 7Write a Python program as per specifications given below:Repeatedly prompt for a sentence (string) or for 'q' to quit.Upon input of a...
Question 8Write a program that does the following :takes two inputs : the first, an integer and the second, a stringfrom the input string extract all...
Question 9Write a program that takes two strings from the user and displays the smaller string in single line and the larger string as per this...
Question 10Write a program to convert a given number into equivalent Roman number (store its value as a string). You can use following guidelines to...
Question 11Write a program that asks the user for a string (only single space between words) and returns an estimate of how many words are in the...
Question 12Write a program to input a formula with some brackets and checks, and prints out if the formula has the same number of opening and closing...
Question 13Write a program that inputs a line of text and prints out the count of vowels in it.Solutionstr = input("Enter a string: ") count = 0 for...
Question 14Write a program to input a line of text and print the biggest word (length wise) from it.Solutionstr = input("Enter a string: ") words =...
Question 15Write a program to input a line of text and create a new line of text where each word of input line is reversed.Solutionstr = input("Enter...