Our Features

Our Features
.

Friday, 17 June 2016

Python Questions and Answers – Strings – 3

This set of Python Technical Interview Questions & Answers focuses on “Strings”.
1. What is the output when following statement is executed ?
  1. >>>chr(ord('A'))
a) A
b) B
c) a
d) Error
View Answer
2. What is the output when following statement is executed ?
  1. >>>print(chr(ord('b')+1))
a) a
b) b
c) c
d) A
View Answer
advertisements
3. 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”)
View Answer
4. Suppose s is “\t\tWorld\n”, what is s.strip() ?
a) \t\tWorld\n
b) \t\tWorld\n
c) \t\tWORLD\n
d) World
View Answer
5. The format function returns :
a) Error
b) int
c) bool
d) str
View Answer
6. What is the output of “hello”+1+2+3 ?
a) hello123
b) hello
c) Error
d) hello6
View Answer
7. What is the output when following code is executed ?
  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) A, B, C, D will be displayed on four lines
View Answer
advertisements
8. What is the output when following statement is executed ?(python 3.xx)
  1. >>>print(format("Welcome", "10s"), end = '#')
  2. >>>print(format(111, "4d"), end = '#')
  3. >>>print(format(924.656, "3.2f"))
a)    Welcome# 111#924.66
b) Welcome#111#924.66
c) Welcome#111#.66
d) Welcome   # 111#924.66
View Answer
9. What will be displayed by print(ord(‘b’) – ord(‘a’)) ?
a) 0
b) 1
c) -1
d) 2
View Answer
10. Say s=”hello” what will be the return value of type(s) ?
a) int
b) bool
c) str
d) String
View Answer
Answer:c
Explanation:str is used to represent strings in python.

No comments:

Post a Comment