Greetings readers, this is our second quiz on Python string functions. This quiz is more towards testing the Python developer skills to a slightly advanced usage of string functions. Almost all the questions will give you a Python illustration to solve. During the quiz, you may need to execute the sample code. So you can start any of these online Python interpreters. We’ve created this test so that any software engineer can check his Python string knowledge. It’s a good option to train in Python online and become aware of the areas for improvement. We always pick the best questions, most of these come from the people who share their experience after going through the Python job interview.
We’ll soon publish a post along with a quiz on data analytics and machine learning. Our effort is always to bring something new and innovate even with the old topics. There is regular brainstorming to ensure the integrity of all the questions and answers. So, please go through the following interview questions for Python programmers. Next, socket programming and multi-threading are some of the important topics that you might want to learn so check this post Complete Guide to Socket Programming for Python Developers. You can refer to it to groom your knowledge of Python sockets.
Solve Quiz – Python String Functions
print(str.center(10, '*'))
Note: You can review all the answers at the end of this quiz. To learn more about the strings in Python, please refer to our guide to Python strings.
Answer Explanations
# | Question | Correct Answer(s) | Explanation |
---|---|---|---|
1 | What will this code output? | *example** | center(10, '*') pads the string to width 10, placing '*' on both sides. |
2 | How does center() work in this code? | *****python***** | center(15, '*') pads the string evenly with '*' on both sides. |
3 | What is the output of count() ? | 2 | Counts occurrences of 'ab' in the string starting from index 2 not from 0th index. |
4 | How many times does 'ab' appear? | 3 | Counts 'ab' within the specified range (-17, -1) . |
5 | Which prints list items on new lines? | print(‘\n’.join(identity)) | join('\n') concatenates list items with newlines. |
6 | Default encoding for str.encode() ? | utf-8 | encode() uses utf-8 by default unless specified otherwise. |
7 | What does expandtabs(4) do? | Welcome To Python Programming | Replaces \t with 4 spaces for uniform spacing. |
8 | Will isnumeric() return True for '2.15' ? | False | isnumeric() only returns True for whole numbers (not decimals). |
9 | What happens when calling lower() ? | hello@john!! | Converts all uppercase letters to lowercase; special characters remain unchanged. |
10 | What does partition('cd') return? | (‘ab’, ‘cd’, ‘efcdyz’) | partition('cd') splits into three parts: before, match, and after. |
11 | How will split('cd', 2) behave? | [‘ab’, ‘ef’, ‘yzcd’] | Splits at 'cd' twice, keeping remaining string intact. |
12 | What does str.title() return? | Python String Concepts | Capitalizes the first letter of each word. |
13 | What is the output of splitlines() ? | [‘PYTHON’, ‘String’, ‘Concepts’] | Splits at \n but removes it from output. |
14 | What does zfill(5) return? | 000am | zfill(5) pads the string with zeros until length is 5 . |
15 | How does zfill() handle '+55' ? | +0055 | zfill(5) ensures width is 5 , keeping + at the start. |
Key Takeaways from the Python String Quiz-2
So, did you enjoy the quiz? We hope you would like to solve the different questions on the Python string functions. Special thanks to you for taking the time to run through this quiz. We urge you not to just leave from here instead try some more cool quizzes and tutorials on Java/Python/Selenium and related programming articles from our blog.
We have a firm belief that spreading knowledge is a step to enhance it further. When readers review our work and share their feedback, they drive us to deliver better. That’s why we always request them to drop their response in the comment box.
Lastly, please share part 2 of the Python string functions with your friends and on the social media platforms of your choice.
All the Best,
TechBeamers