String and list methods

14 important questions on String and list methods

What is the expected output of the following code?

for ch in "def":
    print(chr(ord(ch) + 1), end='')

- The code will output the letters "efg".


What is the expected output?
t = "zeta"
print(t.endswith("a"))
print(t.endswith("A"))
print(t.endswith("et"))
print(t.endswith("eta"))

1. True
2. False
3. False
4. True

What is the expected output?

print('[' + 'thijs'.center(20, '*') + ']')

[*******thijs********]
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

What is the expected output?

t = 'theta'
print(t.find('eta'))
print(t.find('the'))
print(t.find('ha'))

2
0
-1

What is the expected output?

print('kappa'.find('a', 2, 4))

1. Expected output is -1 because 'a' is not found within the specified range of indexes (2, 4).

What is the expected output?


print('30'.isalpha())
print('lambda'.isalpha())
print('lambda30'.isalpha())
print('lambda_30'.isalpha())

False
True
False
False

What is the expected output?


print('30'.isalpha())
print('lambda'.isalpha())
print('lambda30'.isalpha())
print('lambda_30'.isalpha())

False
True
False
False

What is the expected output?


print(",".join(["omicron", "pi", "rho"]))

omicron,pi,rho

What is the expected output?

print("www.cisco.com".lstrip("w."))

- cisco.com
- Removes leading "w." characters from the string.

What is the expected output?


print("This is it!".replace("is", "are", 1))

Thare is it!

What is the expected output?


print("tau tau tau".rfind("ta"))
print("tau tau tau".rfind("ta", 9))
print("tau tau tau".rfind("ta", 3, 9))

8
-1
4

What is the expected output of the following code?

for ch in "abc123XYX":
if ch.isupper(): print(ch.lower(), end='')
elif ch.islower(): print(ch.upper(), end='')
else: print(ch, end='')

ABC123xyx

What is the expected output of the following code?
s1 = 'Where are the snows of yesteryear?'
s2 = s1.split()
print(s2[-2])

Of

What is the expected output of the following code?
s = 'It is either easy or impossible'
s = s.replace('easy', 'hard').replace('im', '')
print(s)

It is either hard or possible

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo