Lecture
Coding Quiz
This coding quiz challenges you to write a function that returns a specific character from a given string using Python's string indexing feature.
Write a function that, given a string and an index number, returns the character at that position.
Parameter Format
def solution(string, index): return # Write your code here
Constraints
-
The input string can include a variety of characters, such as letters, numbers, special characters, etc.
-
The string is not empty.
-
The given index will be within the range of the string. (Including negative indices)
Example Input and Output
-
Input:
("Hello", 0) -
Output:
"H" -
Input:
("Hello, world!", 7) -
Output:
"w" -
Input:
("Data Science", -1) -
Output:
"e"
Lessons in this chapter Β· Data Types in Pythons
- 1. Data Types Representing Kinds of Data
- 2. How to Represent Text, Numbers, and True/False in Python
- 3. How to Check Variable and Value Types
- 4. What to Watch Out for When Creating String Data?
- 5. Understanding and Using Escape Characters
- 6. How to Create Multiline Strings?
- 7. Multiple-choice quiz
- 8. Concatenating Strings with the `+` Operator
- 9. Using the (*) Operator for String Repetition
- 10. Selecting Specific Parts of a String Using Indexing
- 11. How to Select Specific Ranges from a String
- 12. Handling Exceptions with try and except
- 13. String IndexError(index out of range) Exception
- 14. Python String Indexing Coding Quiz
- 15. Multiple-choice quiz
- 16. Fill-in-the-blank quiz
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help