Exit Chapter 09 ยท ๐Ÿ”ค String Manipulation โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 60 0 correct so far

๐Ÿ”ค String Manipulation Quiz

Q1.

For word = "COMPUTER", what does print(word[0], word[5], word[-1], word[-3]) display?

Explanation

Index 0 is C, 5 is T, -1 is R and -3 is T (C0 O1 M2 P3 U4 T5 E6 R7).

Q2.

What happens when you run name = "Rahul" and then name[0] = "M"?

Explanation

Strings are immutable. Build a new string instead: name = "M" + name[1:].

Q3.

What is printed after this code?

s = "hello" s.upper() print(s)

Explanation

upper() returns a NEW string; the result was not stored, so s is unchanged.

Q4.

What does 'traversing a string' mean?

Explanation

Traversing means visiting each character of the string one by one.

Q5.

Which loop gives the INDEX of each character of s?

Explanation

for i in range(len(s)) gives each index i; the character is s[i].

Q6.

What does this code print?

s = "PYTHON" for i in range(len(s) - 1, -1, -1): print(s[i], end="")

Explanation

The indices go from 5 down to 0, so the string is printed in reverse.

Q7.

What is the output of print("10" + "20")?

Explanation
  • on two strings joins them (concatenation); it does not add numbers.
Q8.

What is the result of "Age: " + 16?

Explanation

Both operands of + must be strings; use "Age: " + str(16).

Q9.

What is the output of print(3 * "-=")?

Explanation
  • with a string and an integer repeats the string 3 times.
Q10.

What is the result of "abc" * 0?

Explanation

Repeating a string 0 times gives an empty string.

Q11.

For s = "Informatics", what does print("For" in s) display?

Explanation

Membership is case-sensitive: "for" is in s but "For" is not.

Q12.

What is the output of print("apple" < "apricot")?

Explanation

The first difference is at index 2: 'p' (112) < 'r' (114).

Q13.

What is the output of print("10" < "9")?

Explanation

These are strings compared character by character: '1' (49) < '9' (57).

Q14.

What is the output of print("abc" < "abcd")?

Explanation

When one string is a prefix of the other, the shorter one is smaller.

Q15.

What is the output of print('Python' > 'python')?

Explanation

'P' is 80 and 'p' is 112, so 'Python' is smaller than 'python'.

Q16.

What do ord("A") and chr(97) return?

Explanation

ord() gives a character's Unicode value (A = 65); chr() gives the character for a value (97 = 'a').

Q17.

In string comparison, which order is correct (smallest first)?

Explanation

Digits start at 48, capitals at 65 and small letters at 97.

Q18.

For s = "PROGRAMMING", what is s[3:7]?

Explanation

Indices 3 to 6 (7 is excluded): G, R, A, M.

Q19.

For s = "PROGRAMMING", what is s[7:]?

Explanation

It runs from index 7 to the end: M, I, N, G.

Q20.

For s = "PROGRAMMING", what is s[::2]?

Explanation

Every 2nd character from index 0: indices 0, 2, 4, 6, 8, 10 โ†’ P, O, R, M, I, G.

Q21.

For s = "PROGRAMMING", what is s[-7:-3]?

Explanation

Indices -7 to -4 are R, A, M, M (-3 is excluded).

Q22.

Which slice reverses the whole string s?

Explanation

A step of -1 with default start and stop goes from the end to the beginning.

Q23.

For s = "PROGRAMMING", what is s[5:2]?

Explanation

With the default positive step, you cannot move forward from 5 to 2, so the result is empty.

Q24.

For s = "PROGRAMMING", what is s[8:2:-2]?

Explanation

Going backwards from index 8 in steps of 2: indices 8, 6, 4 โ†’ I, M, R (index 2 is excluded).

Q25.

For s = "Python", which statement is correct?

Explanation

Indexing out of range raises IndexError, but slicing simply stops at the end of the string.

Q26.

For any string s and integer n, s[:n] + s[n:] always equals:

Explanation

Joining the two slices always gives back the full string.

Q27.

For s = "INFORMATICS", what is s[2:6]?

Explanation

Indices 2, 3, 4, 5 give F, O, R, M.

Q28.

For s = "INFORMATICS", what is s[::3]?

Explanation

Indices 0, 3, 6, 9 give I, O, A, C.

Q29.

For s = "INFORMATICS", what is s[7:1:-2]?

Explanation

Going backwards from index 7 in steps of 2: indices 7, 5, 3 give T, M, O.

Q30.

For s = "COMPUTER SCIENCE", what is s[3:8]?

Explanation

Indices 3 to 7 give P, U, T, E, R.

Q31.

What is the output of print("CBSE"[::-1])?

Explanation

A step of -1 reverses the string.

Q32.

What is "hELLO wORLD".capitalize()?

Explanation

capitalize() makes only the first character of the string capital and the rest lowercase.

Q33.

What is "good morning india".title()?

Explanation

title() capitalises the first letter of every word.

Q34.

What is "PyThOn".swapcase()?

Explanation

swapcase() changes uppercase letters to lowercase and lowercase letters to uppercase.

Q35.

What does "banana".count("a") return?

Explanation

The letter 'a' occurs 3 times in 'banana'.

Q36.

What does "banana".find("an") return?

Explanation

find() returns the lowest index where the substring occurs; 'an' first starts at index 1.

Q37.

What does "banana".find("an", 2) return?

Explanation

The search starts at index 2, and the next 'an' begins at index 3.

Q38.

What does "hello".find("z") return?

Explanation

find() returns -1 when the substring is not found.

Q39.

How do find() and index() differ when the substring is NOT found?

Explanation

Both return the lowest index when the substring is found; when it is missing, find() gives -1 but index() raises ValueError.

Q40.

What does "report.pdf".endswith(".pdf") return?

Explanation

endswith() returns True if the string ends with the given substring.

Q41.

What does "Hello World".isalpha() return?

Explanation

The space is not a letter, so isalpha() is False.

Q42.

What does "-5".isdigit() return?

Explanation

'-' is not a digit, so isdigit() is False.

Q43.

What does "abc123".islower() return?

Explanation

Digits are ignored; all the letters are lowercase, so the result is True.

Q44.

Which string makes isalnum() return False?

Explanation

isalnum() needs letters or digits only; the space in "Class 11" makes it False.

Q45.

What does "".isalpha() return?

Explanation

All the is...() methods return False for an empty string.

Q46.

What is " Hi there ".strip()?

Explanation

strip() removes spaces only from the two ends; the spaces between words stay.

Q47.

For s = " Hi there ", what does s.lstrip() return?

Explanation

lstrip() removes only the leading (left) spaces.

Q48.

What is "www.cbse.gov.in".lstrip("w.")?

Explanation

lstrip("w.") removes any leading 'w' and '.' characters from the left end.

Q49.

What is "banana".replace("a", "o")?

Explanation

replace() replaces ALL occurrences of the old substring.

Q50.

What does "10-20-30".split("-") return?

Explanation

split(sep) breaks the string at every separator and returns a list of strings.

Q51.

What does "a,b,,c".split(",") return?

Explanation

The two commas next to each other produce an empty string between them.

Q52.

What is "-".join("2026")?

Explanation

join() puts the separator between the items of the sequence โ€” here, each character.

Q53.

Which is the correct way to join the list lst with '-'?

Explanation

The separator comes first: "-".join(lst). All items must be strings.

Q54.

What does "a=b=c".partition("=") return?

Explanation

partition() splits at the FIRST separator into a 3-part tuple (before, separator, after).

Q55.

What does "hello".partition("@") return?

Explanation

When the separator is not found, the result is (whole string, '', '').

Q56.

Which statement comparing split() and partition() is correct?

Explanation

split() returns a list without the separator; partition() returns (before, separator, after) at the first occurrence.

Q57.

For s = "Python Programming", what does print(s.count("o"), s.find("P", 1), s.upper()[7:10]) display?

Explanation

'o' occurs twice; the next 'P' after index 0 is at 7; the uppercase string's indices 7-9 are P, R, O.

Q58.

What is printed by this code?

msg = "Board@2026" new = "" for ch in msg: if ch.isupper(): new += ch.lower() elif ch.islower(): new += ch.upper() elif ch.isdigit(): new += str(int(ch) + 1) else: new += "#" print(new)

Explanation

Letters swap case, each digit increases by 1 (2026 becomes 3137), and '@' becomes '#'.

Q59.

What does the palindrome check s.lower() == s.lower()[::-1] print for "Madam"?

Explanation

'madam' reversed is 'madam'; converting to lowercase first makes the check ignore case.

Q60.

What does the initials program print for "mohandas karamchand gandhi"?

for part in name.split(): initials += part[0].upper() + "."

Explanation

It takes the first letter of each word, makes it uppercase and adds a dot.