Python Questions and Answers – Strings – 1
This set of Python Questions & Answers focuses on “Strings”.
a) olleh
b) hello
c) h
d) o
View Answer
8. What is the output when following statement is executed ?
1. What is the output when following statement is executed ?
a) a
b) bc
c) bca
d) abc
View Answer
b) bc
c) bca
d) abc
View Answer
Answer:d
Explanation:+ operator is concatenation operator.
Explanation:+ operator is concatenation operator.
2. What is the output when following statement is executed ?
a) a
b) ab
c) cd
d) dc
View Answer
b) ab
c) cd
d) dc
View Answer
Answer:c
Explanation:Slice operation is performed on string.
Explanation:Slice operation is performed on string.
3. 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
View Answer
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase
View Answer
Answer:b
Explanation:Execute in shell and check.
Explanation:Execute in shell and check.
4. What is the output when following code is executed ?
advertisements
b) hello
c) h
d) o
View Answer
Answer:d
Explanation:-1 corresponds to the last index.
Explanation:-1 corresponds to the last index.
5. What arithmetic operators cannot be used with strings ?
a) +
b) *
c) –
d) **
View Answer
a) +
b) *
c) –
d) **
View Answer
Answer:c,d
Explanation:+ is used to concatenate and * is used to multiply strings.
Explanation:+ is used to concatenate and * is used to multiply strings.
6. What is the output when following code is executed ?
The output is
a) a new line and hello
b) \nhello
c) the letter r and then hello
d) Error
View Answer
a) a new line and hello
b) \nhello
c) the letter r and then hello
d) Error
View Answer
Answer:b
Explanation:When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw string and the escape sequences such as \n are not converted.
Explanation:When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw string and the escape sequences such as \n are not converted.
7. What is the output when following statement is executed ?
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
View Answer
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
View Answer
Answer:c
Explanation:String literals seperated by white space are allowed. They are concatenated.
Explanation:String literals seperated by white space are allowed. They are concatenated.
advertisements
a) Error
b) 97
98
c) _~
d) \x97\x98
View Answer
b) 97
98
c) _~
d) \x97\x98
View Answer
Answer:c
Explanation:\x is an escape sequence that means the following 2 digits are a hexadicmal number encoding a character.
Explanation:\x is an escape sequence that means the following 2 digits are a hexadicmal number encoding a character.
9. What is the output when following code is executed ?
a) dlrowolleh
b) hello
c) world
d) helloworld
View Answer
b) hello
c) world
d) helloworld
View Answer
Answer:a
Explanation:Execute in shell to verify.
Explanation:Execute in shell to verify.
10. print 0xA + 0xB + 0xC :
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
View Answer
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
View Answer
Answer:d
Explanation:0xA and 0xB and 0xC are hexadecimal integer literals representing the decimal values 10,11 and 12 respectively. There sum is 33.
Explanation:0xA and 0xB and 0xC are hexadecimal integer literals representing the decimal values 10,11 and 12 respectively. There sum is 33.
No comments:
Post a Comment