String Manipulation in Python Questions and Answers Class 11-12

 

Q.1 : Which  of  the  following returns a copy of  the string with its first character  capitalized ?

a) string.upper()

b) string.capitalize()

c) capitalize()

d) all  of these

 

Q.2:Which of the following  is not a python legal string operation ?

a) ‘abc’ + ‘abc’

b) ‘abc’ * 3

c) ‘abc’ + 3

d) ‘abc’.lower()

 

Q.3: Out  of  the following  operators , which one  cannot  be used with strings ?

a) <>

b) *

c) +

d) in

 

Q.4: The _________ function  returns the ASCII value  of given character ?

a) ord()

b) chr()

c) varchar()

d) none of these

 

Q.5 : For  a string  s  storing ‘Goldy’ what would s[0]  and s[-1]  return ?

a) g ,y

b) G,y

c) G,d

d) None

 

Q.6 : ________ refers to iterating  through  the elements  of  a string , one character at a time.

Answer : Traversing

 

Q.7 : What is the output  produced  by  following expressions ?

  1. “The “

 

Q. 8: What  do you understand by string slices?

Answer : Slicing is the process of obtaining a portion (substring) of a string by using its indices. Given a string, we can use the following template to slice it and obtain a substring: string[start:end] start is the index from where we want the substring to start.

 

Q. 9: What  is the role of these functions ?

a) isalpha()

b) isalnum()

c) isdigit()

d) isspace()

 

Answer:

isalpha() : returns true if there all  characters in string are alphabetic

isalnum(): returns True if all the characters are alphanumeric

isdigit(): returns True if all the characters are digits

isspace(): returns True if all the characters in a string are whitespaces

 

 

Q. 10 : What  are membership operators? What do they basically do?

Answer :

The membership operators are, as the name explains, used to verify a value membership. The operators are used to figure out if there are two forms of value as a part of a sequence, such as string or list membership operators: in and not in

The last character of a string S is at index len(s) -1 . (True/False)

 

Q. 11 : How are string internally  stored?

Answer :

Python stores strings as sequences of unicode characters. Unicode characters are stored with either 1, 2, or 4 bytes depending on the size of their encoding. Byte size of strings increases proportionally with the size of its largest character, since all characters must be of the same size.

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved
error: Content is protected !!