Question 1
EasyWhat is the output of this code?
s = "hello"
print(s[::-1])
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the output of this code?
s = "hello"
print(s[::-1])
olleh
o
h
hello
Answer: A
Slicing with step −1 reverses the string.
What is the output of this code?
print(len("hello"))
5
4
6
Error
Answer: A
len() counts the characters: h, e, l, l, o.
What is a palindrome?
A string that reads the same forwards and backwards
A string with only vowels
A string with no repeated characters
A string of numbers
Answer: A
For example, 'madam' and 'racecar'.
What is the output of this code?
print("hello".find("l"))
2
3
1
-1
Answer: A
find() returns the index of the first occurrence: 'l' first appears at index 2 (h = 0, e = 1).
Are Python and Java strings mutable?
No, they are immutable: operations create new strings
Only Python strings are mutable
Only Java strings are mutable
Yes, they can be changed in place
Answer: A
Methods like replace or upper return new strings; the original is unchanged.
What is the output of this code?
print("banana".count("a"))
4
3
1
2
Answer: B
count returns the number of non-overlapping occurrences: "banana" has three a's.
What are two strings called if they contain the same characters with the same counts, in any order?
Anagrams
Palindromes
Substrings
Prefixes
Answer: A
For example, 'listen' and 'silent'.
What is the length of the string 'hello world'?
2
10
11
12
Answer: C
5 letters + 1 space + 5 letters = 11 characters.
What is a substring?
A contiguous sequence of characters inside a string
Any set of characters from the string
The string in reverse
The first character only
Answer: A
'ell' is a substring of 'hello'; 'hlo' is not.
What is the output of this code?
print('abc'[::-1])
Error
cba
bca
abc
Answer: B
A slice with step −1 reverses the string.