Thursday, 30 July 2020

PYTHON GTU MCQ (CH-3 Python Strings)

PYTHON 
[SUBJECT CODE: 2180711]
CH-3 PYTHON STRINGS


Topics Covers:-

  • Strings and Input
  • Strings
  • Tuples
  • Lists and Dictionaries
MCQ:-

1.The output of executing string.ascii_letters can also be achieved by:
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase

2.What arithmetic operators cannot be used with strings?
a) +
b) *
c) –
d) All of the mentioned

3.print(0xA + 0xB + 0xC):
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33

 4.What will be the output of the following Python code?

1. class father:
2.     def __init__(self, param):
3.         self.o1 = param
4.  
5. class child(father):
6.     def __init__(self, param):
7.         self.o2 = param
8.  
9. >>>obj = child(22)
10. >>>print "%d %d" % (obj.o1, obj.o2)

a) None None
b) None 22
c) 22 None
d) Error is generated

 5.What will be the output of the following Python code?

1. >>>example = "helle"
2. >>>example.rfind("e")

a) -1
b) 4
c) 3
d) 1

6.To concatenate two strings to a third what statements are applicable?
a) s3 = s1 . s2
b) s3 = s1.add(s2)
c) s3 = s1.__add__(s2)
d) s3 = s1 * s2

7.Which of the following statement prints hello\example\test.txt?
a) print(“hello\example\test.txt”)
b) print(“hello\\example\\test.txt”)
c) print(“hello\”example\”test.txt”)
d) print(“hello”\example”\test.txt”)

8.Suppose s is “\t\tWorld\n”, what is s.strip()?
a) \t\tWorld\n
b) \t\tWorld\n
c) \t\tWORLD\n
d) World

9.The format function, when applied on a string returns ___________
a) Error
b) int
c) bool
d) str

10.What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6

11.What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6

12.To return the length of string s what command do we execute?
a) s.__len__()
b) len(s)
c) size(s)
d) s.size()

13.If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.
a) obj.__str__()
b) str(obj)
c) print obj
d) all of the mentioned

14.To check whether string s1 contains another string s2, use ________
a) s1.__contains__(s2)
b) s2 in s1
c) s1.contains(s2)
d) si.in(s2)

 15.What will be the output of the following Python code?

1. class Count:
2.     def __init__(self, count = 0):
3.     self.__count = count
4.  
5. c1 = Count(2)
6. c2 = Count(2)
7. print(id(c1) == id(c2), end = " ")  
9. s1 = "Good"
10.s2 = "Good"
11.print(id(s1) == id(s2))
\

a) True False
b) True True
c) False True
d) False False

16.What will be the output of the following Python code?

1. class Name:
2.     def __init__(self, firstName, mi, lastName):
3.         self.firstName = firstName
4.         self.mi = mi
5.         self.lastName = lastName
7. firstName = "John"
8. name = Name(firstName, 'F', "Smith")
9. firstName = "Peter"
10.name.lastName = "Pan"
11.print(name.firstName, name.lastName)

a) Peter Pan
b) John Pan
c) Peter Smith
d) John Smith

17.What function do you use to read a string?
a) input(“Enter a string”)
b) eval(input(“Enter a string”))
c) enter(“Enter a string”)

d) eval(enter(“Enter a string”))

18.What will be the output of the following Python code?

print('*', "abcdef".center(7), '*')

a) * abcdef *
b) * abcdef *
c) *abcdef *
d) * abcdef*

19.What will be the output of the following Python code?

print('*', "abcde".center(6), '*', sep='')

a) * abcde *
b) * abcde *
c) *abcde *
d) * abcde*

20.What will be the output of the following Python code?

print("abcdef".center(7, '1'))

a) 1abcdef
b) abcdef1
c) abcdef
d) error

 21.What will be the output of the following Python code?

print("abcdef".center(10, '12'))

a) 12abcdef12
b) abcdef1212
c) 1212abcdef
d) error

22.What will be displayed by print(ord(‘b’) – ord(‘a’))?
a) 0
b) 1
c) -1
d) 2

23.What will be the output of the following Python code?

1. >>>print("D", end = ' ')
2. >>>print("C", end = ' ')
3. >>>print("B", end = ' ')
4. >>>print("A", end = ' ')

a) DCBA
b) A, B, C, D
c) D C B A
d) D, C, B, A will be displayed on four lines

24.What will be the output of the following Python code?

1. >>>example="helloworld"
2. >>>example[::-1].startswith("d")

a) dlrowolleh
b) True
c) -1
d) None

 25.What will be the output of the following Python code?

1. >>>example = "helle"
2. >>>example.find("e")

a) Error
b) -1
c) 1
d) 0



More MCQ Uploading Soon... Stay Tune
Comment Your View In Below Section.. it's Very Helpful...

0 Comments:

Post a Comment