Strings Deep-Dive — Methods, Formatting & Unicode — Concept Check
Questions on Strings Deep-Dive — Methods, Formatting & Unicode. The string methods that solve interview problems — split/join/strip/find/replace, is* checks, format specs — plus the bytes-vs-str boundary every backend engineer must respect.
Questions in this quiz
8 questions on Strings Deep-Dive — Methods, Formatting & Unicode — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer is trying to count occurrences of the letter 'c' in a string 'CodeCampus'. Which method should they use?
- A'CodeCampus'.replace('c', '')
- B'CodeCampus'.split('c')
- C'CodeCampus'.count('c')
- D'CodeCampus'.find('c')
2.You have a CSV string 'name,age,location' and need to convert it into a list. Which method should you use?
- A'name,age,location'.split(',')
- B'name,age,location'.join(',')
- C'name,age,location'.replace(',', ' ')
- D'name,age,location'.strip(',')
3.A file read operation in Python returns a bytes object. What should you do to handle it as a string?
- AConcatenate it with a str object
- BDirectly print the bytes object
- CUse decode() on the bytes object
- DUse encode() on the bytes object
4.A developer mistakenly tries to concatenate a str and bytes object. What error will occur?
- ATypeError
- BSyntaxError
- CIndexError
- DValueError
5.A string ' Hello World ' needs trimming of spaces on both ends. Which method is appropriate?
- A' Hello World '.join()
- B' Hello World '.strip()
- C' Hello World '.replace(' ', '')
- D' Hello World '.split()
6.A developer uses 'abc'.encode('utf-8'). What type is the result?
- Alist
- Bbytes
- Cstr
- Ddict
7.Why might 'abc'.startswith(('a', 'b')) return True?
- A'abc' contains 'a' or 'b'
- B'abc' starts with 'a'
- C'abc' ends with 'a' or 'b'
- D'abc' starts with 'b'
8.A string 'Python' needs to be checked if it is alphanumeric. Which method should be used?
- A'Python'.isdigit()
- B'Python'.isalnum()
- C'Python'.isnumeric()
- D'Python'.isalpha()