String in Python

Qus. 1 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">x = "abcdef"<br></span><span style="font-size: 14px;">i = "a"<br></span><span style="font-size: 14px;">while i in x:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; x = x[:-1]<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(i, end = " ")</span></pre>

  1. i i i i i i
  2. a a a a a a
  3. a a a a a
  4. none of the mentioned
Qus. 2 : <p>What will be the output of the following Python code?</p> <pre class="de1" style="border-radius: 0px; padding: 0px; font-family: Consolas, Monaco, " lucida="" console",="" monospace;="" color:="" rgb(51,="" 51,="" 51);="" word-break:="" break-all;="" overflow-wrap:="" normal;="" background:="" rgb(244,="" 244,="" 244);="" border:="" 0px;="" overflow:="" visible;="" box-shadow:="" none;="" text-align:="" justify;="" margin-top:="" 0px="" !important;="" margin-bottom:="" line-height:="" 20px="" !important;"=""> <span style="font-size: 12.6px;">x = "abcdef" i = "a" while i in x[:-1]: print(i, end = " ")</span></pre>

  1. a a a a a
  2. a a a a a a
  3. a a a a a a … infinite Time
  4. a
Qus. 3 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">x = "abcdef"<br></span><span style="font-size: 14px;">i = "a"<br></span><span style="font-size: 14px;">while i in x:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; x = x[1:]<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(i, end = " ")</span></pre>

  1. a a a a a a
  2. a
  3. no output
  4. error
Qus. 4 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">x = 'abcd'<br></span><span style="font-size: 14px;">for i in x:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(i)<br></span><span style="font-size: 14px;">&nbsp; &nbsp; x.upper()</span></pre>

  1. a B C D
  2. a b c d
  3. A B C D
  4. error
Qus. 5 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">x = 'abcd'<br></span><span style="font-size: 14px;">for i in range(len(x)):<br></span><span style="font-size: 14px;">&nbsp; &nbsp; x[i].upper()<br></span><span style="font-size: 14px;">print (x)</span></pre><div><br></div>

  1. abcd
  2. ABCD
  3. error
  4. none of the mentioned
Qus. 6 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">string = "my name is x"<br></span><span style="font-size: 14px;">for i in string:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print (i, end=", ")</span></pre>

  1. m, y, , n, a, m, e, , i, s, , x,
  2. m, y, , n, a, m, e, , i, s, , x
  3. my, name, is, x,
  4. error
Qus. 7 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">string = "my name is x"<br></span><span style="font-size: 14px;">for i in string.split():<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print (i, end=", ")</span></pre>

  1. m, y, , n, a, m, e, , i, s, , x,
  2. m, y, , n, a, m, e, , i, s, , x
  3. my, name, is, x,
  4. error
Qus. 8 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">a = [0, 1, 2, 3]<br></span><span style="font-size: 14px;">for a[0] in a:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print(a[0])</span></pre>

  1. 0 1 2 3
  2. 0 1 2 2
  3. 3 3 3 3
  4. error
Qus. 9 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">str1="helloworld"<br></span><span style="font-size: 14px;">print(str1[::-1])</span></pre>

  1. dlrowolleh
  2. hello
  3. world
  4. helloworld
Qus. 10 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">example = "snow world"<br></span><span style="font-size: 14px;">example[3] = 's'<br></span><span style="font-size: 14px;">print (example)</span></pre><div><br></div>

  1. snow
  2. snow world
  3. Error
  4. snos world
Qus. 11 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print(max("what are you"))</span></pre>

  1. error
  2. u
  3. t
  4. y
Qus. 12 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">example = "helle"<br></span><span style="font-size: 14px;">print(example.find("e"))</span></pre>

  1. Error
  2. -1
  3. 1
  4. 0
Qus. 13 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">example = "helle"<br></span><span style="font-size: 14px;">print(example.rfind("e"))</span></pre>

  1. -1
  2. 4
  3. 3
  4. 1
Qus. 14 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("abc DEF".capitalize())</span></pre>

  1. abc def
  2. ABC DEF
  3. Abc def
  4. Abc Def
Qus. 15 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("xyyzxyzxzxyy".count('yy', 1))</span></pre>

  1. 2
  2. 0
  3. 1
  4. none of the mentioned
Qus. 16 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("xyyzxyzxzxyy".count('xyy', 2, 11))</span></pre>

  1. 2
  2. 0
  3. 1
  4. error
Qus. 17 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("xyyzxyzxzxyy".count('xyy', -10, -1))</span></pre>

  1. 2
  2. 0
  3. 1
  4. error
Qus. 18 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("xyyzxyzxzxyy".endswith("xyy"))</span></pre>

  1. 1
  2. True
  3. 3
  4. 2
Qus. 19 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("xyyzxyzxzxyy".endswith("xyy", 0, 2))</span></pre><div><br></div>

  1. 0
  2. 1
  3. True
  4. False
Qus. 20 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("abcdef".find("cd") == "cd" in "abcdef")</span></pre>

  1. True
  2. False
  3. Error
  4. None of the mentioned
Qus. 21 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("abcdef".find("cd"))</span></pre><div><br></div>

  1. True
  2. 2
  3. 3
  4. None of the mentioned
Qus. 22 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('ab,12'.isalnum())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 23 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('ab'.isalpha())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 24 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('a B'.isalpha())</span></pre><div><br></div>

  1. True
  2. False
  3. None
  4. Error
Qus. 25 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print(''.isdigit())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 26 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abc'.islower())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 27 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('a@ 1,'.islower())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 28 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('11'.isnumeric())</span></pre><div><br></div>

  1. True
  2. False
  3. None
  4. Error
Qus. 29 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('1.1'.isnumeric())</span></pre><div><br></div><div><br></div><p><br></p>

  1. True
  2. False
  3. None
  4. Error
Qus. 30 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('HelloWorld'.istitle())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 31 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('Hello World'.istitle())</span></pre>

  1. True
  2. False
  3. None
  4. Error
Qus. 32 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('Hello!2@#World'.istitle())</span></pre>

  1. True
  2. False
  3. None
  4. error
Qus. 33 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('xyyzxxyxyy'.lstrip('xyy'))</span></pre>

  1. error
  2. zxxyxyy
  3. z
  4. zxxy
Qus. 34 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('xyxxyyzxxy'.lstrip('xyy'))</span></pre>

  1. zxxy
  2. xyxxyyzxxy
  3. xyxzxxy
  4. none of the mentioned
Qus. 35 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('abcdef'.partition('cd'))</span></pre>

  1. (‘ab’, ‘ef’)
  2. (‘abef’)
  3. (‘ab’, ‘cd’, ‘ef’)
  4. 2
Qus. 36 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('abcdefcdgh'.partition('cd'))</span></pre>

  1. (‘ab’, ‘cd’, ‘ef’, ‘cd’, ‘gh’)
  2. (‘ab’, ‘cd’, ‘efcdgh’)
  3. (‘abcdef’, ‘cd’, ‘gh’)
  4. error
Qus. 37 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('abcd'.partition('cd'))</span></pre>

  1. (‘ab’, ‘cd’, ”)
  2. (‘ab’, ‘cd’)
  3. error
  4. none of the mentioned
Qus. 38 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('cd'.partition('cd'))</span></pre>

  1. (‘cd’)
  2. (”)
  3. (‘cd’, ”, ”)
  4. (”, ‘cd’, ”)
Qus. 39 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abef'.partition('cd'))</span></pre>

  1. (‘abef’)
  2. (‘abef’, ‘cd’, ”)
  3. (‘abef’, ”, ”)
  4. error
Qus. 40 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abcdef12'.replace('cd', '12'))</span></pre>

  1. ab12ef12
  2. abcdef12
  3. ab12efcd
  4. none of the mentioned
Qus. 41 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abef'.replace('cd', '12'))</span></pre>

  1. abef
  2. 12
  3. error
  4. none of the mentioned
Qus. 42 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abcefd'.replace('cd', '12'))</span></pre>

  1. ab1ef2
  2. abcefd
  3. ab1efd
  4. ab12ed2
Qus. 43 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('xyyxyyxyxyxxy'.replace('xy', '12', 100))</span></pre>

  1. xyyxyyxyxyxxy
  2. 12y12y1212x12
  3. none of the mentioned
  4. error
Qus. 44 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abcdefcdghcd'.split('cd'))</span></pre>

  1. [‘ab’, ‘ef’, ‘gh’]
  2. [‘ab’, ‘ef’, ‘gh’, ”]
  3. (‘ab’, ‘ef’, ‘gh’)
  4. (‘ab’, ‘ef’, ‘gh’, ”)
Qus. 45 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abcdefcdghcd'.split('cd', 0))</span></pre>

  1. [‘abcdefcdghcd’]
  2. ‘abcdefcdghcd’
  3. error
  4. none of the mentioned
Qus. 46 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abcdefcdghcd'.split('cd', -1))</span></pre>

  1. [‘ab’, ‘ef’, ‘gh’]
  2. [‘ab’, ‘ef’, ‘gh’, ”]
  3. (‘ab’, ‘ef’, ‘gh’)
  4. (‘ab’, ‘ef’, ‘gh’, ”)
Qus. 47 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('abcdefcdghcd'.split('cd', 2))</span></pre>

  1. [‘ab’, ‘ef’, ‘ghcd’]
  2. [‘ab’, ‘efcdghcd’]
  3. [‘abcdef’, ‘ghcd’]
  4. none of the mentioned
Qus. 48 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('Ab!2'.swapcase())</span></pre>

  1. AB!@
  2. ab12
  3. aB!2
  4. aB1@
Qus. 49 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('ab cd ef'.title())</span></pre>

  1. Ab cd ef
  2. Ab cd eF
  3. Ab Cd Ef
  4. None of the mentioned
Qus. 50 : <p>What will be the output of the following Python code snippet?</p><pre><span style="font-size: 14px;">print('ab cd-ef'.title())</span></pre>

  1. Ab cd-ef
  2. Ab Cd-ef
  3. Ab Cd-Ef
  4. None of the mentioned
Qus. 51 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print("Welcome to Python".split())</span></pre>

  1. [“Welcome”, “to”, “Python”]
  2. (“Welcome”, “to”, “Python”)
  3. {“Welcome”, “to”, “Python”}
  4. “Welcome”, “to”, “Python”
Qus. 52 : If wd="Hello World" then which of the following statements will display last five characters of the string object?

  1. wd[4:]
  2. wd[:4]
  3. wd[-5:]
  4. wd[:-4]
Qus. 53 : lstrip() method is used for :

  1. delete all the trailing whitespace characters
  2. delete all the leading whitespace characters
  3. delete all the leading and trailing whitespace characters
  4. delete upper case characters
Qus. 54 : <p>What does the following code print ?</p><pre>x = 'mohan'<br>for i in range (len(x)):<br>&nbsp; &nbsp; &nbsp; &nbsp;x[i].upper()<br>print (x)</pre><div><br></div>

  1. mohan
  2. MOHAN
  3. Error
  4. None of These
Qus. 55 : What is the output of >>>’2’ +’3’

  1. 23
  2. '2+3'
  3. '23'
  4. None of These
Qus. 56 : <p>What will be the output of the following expression?</p><pre><span style="font-size: 14px;">a = 2<br></span><span style="font-size: 14px;">b = 8<br></span><span style="font-size: 14px;">print(a|b )<br></span><span style="font-size: 14px;">print(a &gt;&gt; 1)</span></pre>

  1. 10 0
  2. 10 2
  3. 2 2
  4. 10 1
Qus. 57 : When we open file in append mode the file pointer is at the of the file?

  1. anywhere in between the file
  2. End
  3. beginning
  4. second line of the file
Qus. 58 : <p>What will be the output of following statement ?</p><pre>&gt;&gt;&gt;"m"+"n1"</pre>

  1. 'm+nl'
  2. 'mn1'
  3. 'm n1'
  4. 'm'
Qus. 59 : which of the following are valid string manipulation function in python

  1. count()
  2. strip()
  3. upper()
  4. उपरोक्त सभी
Qus. 60 : Which predefined Python function is used to find length of String()

  1. length
  2. length()
  3. len()
  4. None
Qus. 61 : Each individual character in a string can be accessed using a technique called _____ .

  1. indexing
  2. Replication
  3. concatenation
  4. None of the Above
Qus. 62 : Python allows ____ operations on string data type .

  1. Concatenation
  2. Membership
  3. Slicing
  4. All of the above
Qus. 63 : Which method is used to access some part of a string or substring.

  1. slicer
  2. Slicing
  3. Membership
  4. None of these-
Qus. 64 : str[11 : 5] will return ____ .

  1. empty string
  2. complete string
  3. string of six characters
  4. None of the above
Qus. 65 : What does the function re.match do?

  1. matches a pattern at the start of the string.
  2. matches a pattern at any position in the string.
  3. such a function does not exist
  4. none of the mentioned
Qus. 66 : str[5 : 11] will return ______ characters.

  1. 5
  2. 6
  3. 11
  4. None
Qus. 67 : What does the function re-search do?

  1. matches a pattern at the start of the string.
  2. matches a pattern at any position in the string.
  3. such a function does not exist
  4. none of the mentioned.
Qus. 68 : Which of the following function returns True if the string is non empty and has all uppercase alphabets.

  1. islower()
  2. isupper()
  3. Islower()
  4. None
Qus. 69 : Which of the following will return reverse string str1?

  1. str1[ : : -1 ]
  2. str1[ : : 1 ]
  3. str1[ : -1 : -1 ]
  4. None
Qus. 70 : Which function returns the exact copy of the string with the first letter in uppercase.

  1. find()
  2. copy()
  3. upper()
  4. capitalize()
Qus. 71 : split( ) function returns the _____ of words delimited by the specified substring.

  1. List
  2. Tuple
  3. Dictionary
  4. None
Qus. 72 : If no delimiter is given in split() function then words are separated by

  1. space
  2. colon
  3. semi colon
  4. None
Qus. 73 : Which of the following function returns the index value of first occurrence of substring occurring in the given string.

  1. index()
  2. find()
  3. Both of the above
  4. None of the above
Qus. 74 : <p>what will the output of following code</p><pre><span style="font-size: 14px;">my_string="Hello,world"<br></span><span style="font-size: 14px;">print(my_string[-6:-1])</span></pre>

  1. ,worl
  2. worl
  3. world
  4. oworld
Qus. 75 : <p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">&gt;&gt;&gt;max("what are you")</span></pre>

  1. what
  2. y
  3. a
  4. Error
Qus. 76 : "hello,world"[-6], what value print?

  1. White Space
  2. ,
  3. e
  4. S
Qus. 77 : Which of the following are valid string manipulation functions in python?

  1. count()
  2. upper()
  3. strip()
  4. All the above
Qus. 78 : <p>What is the output of the following program:</p><pre><span style="font-size: 14px;">print ("Hello World"[::-1])</span></pre>

  1. dlroW olleH
  2. Hello Worl
  3. D
  4. error

Programs

python program to find the 2nd largest number from the list of the numbers entered through keyboard.

View Solution


python program that creates a list of numbers from 1 to 20 that are divisible by 4

View Solution


python program to define a list of countries that are a member of BRICS Check whether a county is member of BRICS or not

View Solution


Python program to read marks of six subjects and to print the marks scored in each subject and show the total marks

View Solution


Python program to read prices of 5 items in a list and then display sum of all the prices product of all the prices and find the average

View Solution


Python program to count the number of employees earning more than 1 lakh per annum

View Solution


python program to create a list of numbers in the range 1 to 10 Then delete all the even numbers from the list and print the final list

View Solution


python program to generate in the Fibonacci series and store it in a list Then find the sum of all values

View Solution


python program to swap two values using tuple assignment

View Solution


python program using a function that returns the area and circumference of a circle whose radius is passed as an argument

View Solution


python program that has a list of positive and negative numbers Create a new tuple that has only positive numbers from the list

View Solution


Python Program that generate a set of prime numbers and another set of even numbers

View Solution


python program to find minimum element from a list of elements along with its index in the list

View Solution


Python program to calculate mean of a given list of numbers

View Solution


Python program to search for an element in a given list of numbers

View Solution


python program to count frequency of a given element in a list of numbers

View Solution


python program to calculate the sum of integers of the list

View Solution


python program to reverses an array of integers

View Solution


python program to creates a third list after adding two lists

View Solution


python program to store the product information in dictionary

View Solution


python program to create a dictionary whose keys are month names and values are their corresponding number of days

View Solution


python program that input a list, replace it twice and then prints the sorted list in ascending and descending order

View Solution


python program to check if the maximum element of the list lies in the first half of the list or in the second half

View Solution


python program to display the maximum elements from the two list along with its index in its list

View Solution


python program to swap list elements with even and locations

View Solution


python program to rotate list elements with next elements

View Solution


python program to find maximum and minimum values in tuple

View Solution


python program to interchange the values of two tuple

View Solution


python program to interchange the values of two tuple

View Solution


python program to increment the elements of list

View Solution


python program to enter a list containing number between 1 and 12 then replace all the entries in the list that are greater than 10 with 10

View Solution


python program that reverse the list of integers in place

View Solution


python program to input two list and create third list which contains all elements of the first elements followed by all elements of second list

View Solution


python program to inter list of string and create a new list that consist of those strings with their first characters removed

View Solution


python program to create a list using for loop which consist of integers 0 through 49

View Solution


python program to create a list using for loop which consist square of the integers 1 through 50

View Solution


python program to create a list using for loop which consist a bb ccc dddd that ends with 26 copies of the letter z.

View Solution


python program that takes any two list L and M of the same size and adds their elements together in another third list

View Solution


python program to rotates the elements of list so that fist elements move to second and second to the third

View Solution


python program to move all duplicate element to the end of list

View Solution


python program to display the maximum and minimum values form specified range of indexes of a list

View Solution


python program to compare two equal sized list and print the first index where they differ

View Solution


python program to enter names of employees and their salaries as input and store them in a dictionary

View Solution


python program to count the number of times a character appears in a given string

View Solution


python program to convert a number entered by the user into its corresponding number in words

View Solution


python program Repeatedly ask the user to enter a team name

View Solution


python program that repeatedly asks the user to enter product names and prices

View Solution


Python Program to Create a dictionary whose keys are month name and whose values are number of days in the corresponding month

View Solution


python program to store the detail of 10 students in a dictionary at the same time

View Solution


python program to Create a dictionary with the opposite mapping

View Solution


python program that lists the over lapping keys of the two dictionaries if a key of d1 is also a key of d2 the list it

View Solution


python program that checks if two same values in a dictionary have different keys

View Solution


python program to check if a dictionary is contained in another dictionary

View Solution


python program to create a new dictionary D2 having same keys as D1 but values as the sum of the list elements

View Solution


python program to create a dictionary has three keys assets liabilities and capital

View Solution


python program that create a tuple storing first 9 terms of Fibonacci series

View Solution


python program that receives the index and return the corresponding value

View Solution


Python program that receives a Fibonacci series term and returns a number telling which term it is

View Solution


python program to create a nested tuple to store roll number name and marks of students

View Solution


python program that interactively creates a nested tuple to store the marks in three subjects for five students

View Solution


Python Program to accept three distinct digits and print all possible combinations from the digits

View Solution


Python Program to find the successor and predecessor of the largest element in list

View Solution


Python function that takes a string as parameter and returns a string with every successive repetitive character replaced

View Solution


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad