Which fix removes the bug?
name = 'report.txt'.strip('.txt')
print(name) # expected report
- Use
rstrip('.txt')instead - Use
removesuffix('.txt') - Use
lstrip('.txt')instead - Use
split('.txt')[1]here
strip removes any of the characters . t x from both ends, eating the final t of 'report' too.
Play Problem Solving ▸