To retrieve the character at index 3 from string s=βHelloβ what command do we execute (multiple answers allowed)?
Anonymous Quiz
18%
s[]
36%
s.getitem(3)
26%
s.__getitem__(3)
20%
s.getItem(3)
β€1
To return the length of string s what command do we execute?
Anonymous Quiz
44%
len(s) OR s.__len__()
43%
len(s) only
7%
size(s)
7%
s.size()
π1
Explanation:
len(s) is a built-in function in Python to get the length of the string s, whereas s.len() calls the len method of the string object s. Itβs less common but functionally equivalent to len(s). So, we can use either of these.
len(s) is a built-in function in Python to get the length of the string s, whereas s.len() calls the len method of the string object s. Itβs less common but functionally equivalent to len(s). So, we can use either of these.
To check whether string s1 contains another string s2, use ________
Anonymous Quiz
30%
s1.__contains__(s2)
33%
s2 in s1
32%
s1.contains(s2)
6%
si.in(s2)
π4
What will be the output of the following Python code?
print("abc DEF".capitalize())
print("abc DEF".capitalize())
Anonymous Quiz
7%
abc def
59%
ABC DEF
20%
Abc def
14%
Abc Def
What will be the output of the following Python code?
print("abc. DEF".capitalize())
print("abc. DEF".capitalize())
Anonymous Quiz
7%
abc. def
39%
ABC. DEF
32%
Abc. def
22%
Abc. Def
π€―2
What will be the output of the following Python code?
print("abcdef".center())
print("abcdef".center())
Anonymous Quiz
43%
cd
24%
abcde
24%
error
9%
none
β€3π1
What will be the output of the following Python code?
print("abcdef".center(0))
print("abcdef".center(0))
Anonymous Quiz
27%
cd
26%
abcdef
34%
error
13%
None
What will be the output of the following Python code?
print('*', "abcdef".center(7), '*')
print('*', "abcdef".center(7), '*')
Anonymous Quiz
36%
* abcdef *
47%
*abcdef *
17%
* abcdef*
What will be the output of the following Python code?
print('*', "abcdef".center(7), '*', sep='')
print('*', "abcdef".center(7), '*', sep='')
Anonymous Quiz
31%
* abcdef *
35%
* abcdef *
22%
*abcdef *
12%
* abcdef*
β€1
What will be the output of the following Python code?
print("abcdef".center(7, 1))
print("abcdef".center(7, 1))
Anonymous Quiz
23%
1abcdef
40%
abcdef1
11%
abcdef
25%
error
π2
What will be the output of the following Python code?
print("abcdef".center(7, '1'))
print("abcdef".center(7, '1'))
Anonymous Quiz
18%
1abcdef
43%
abcdef1
8%
abcdef
30%
error
π2
What will be the output of the following Python code?
print("abcdef".center(10, '12'))
print("abcdef".center(10, '12'))
Anonymous Quiz
43%
12abcdef12
22%
abcdef1212
13%
1212abcdef
23%
error
π€―2
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
print("xyyzxyzxzxyy".count('yy'))
Anonymous Quiz
61%
2
8%
0
26%
error
5%
none
π3
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 1))
print("xyyzxyzxzxyy".count('yy', 1))
Anonymous Quiz
42%
2
15%
0
32%
1
11%
none
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 2))
print("xyyzxyzxzxyy".count('yy', 2))
Anonymous Quiz
44%
2
14%
0
33%
1
10%
none
π1π€1
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 0, 100))
print("xyyzxyzxzxyy".count('xyy', 0, 100))
Anonymous Quiz
44%
2
18%
0
16%
1
22%
error
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 2, 11))
print("xyyzxyzxzxyy".count('xyy', 2, 11))
Anonymous Quiz
32%
2
19%
0
37%
1
12%
error
β€2π₯1
What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', -10, -1))
print("xyyzxyzxzxyy".count('xyy', -10, -1))
Anonymous Quiz
25%
2
32%
0
18%
1
25%
error
What will be the output of the following Python code?
print('abc'.encode())
print('abc'.encode())
Anonymous Quiz
38%
abc
31%
βabcβ
20%
bβabcβ
11%
hβabcβ