PCEP String Operations and Methods Flashcards
6 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 PCEP String Operations and Methods flashcards as text
What is the output of `len('Python 3')`?
Answer: 8
`len()` counts all characters including spaces, so 'Python 3' has 8 characters.
Which method replaces all occurrences of a substring in a string?
Answer: replace()
`replace(old, new)` returns a new string with all occurrences of `old` replaced by `new`.
What does `'Python'.find('th')` return?
Answer: 2
`find()` returns the index of the first occurrence of the substring; 'th' starts at index 2.
What is the output of `'-'.join(['a', 'b', 'c'])`?
Answer: a-b-c
`join()` concatenates list elements with the calling string as a separator between each item.
What does `'Hello World'.lower()` return?
Answer: hello world
`lower()` converts every character in the string to lowercase.
Which escape sequence represents a newline character in a Python string?
Answer: \n
`\n` is the escape sequence for a newline, which moves output to the next line.