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 `'Python'[-1]`?
Answer: n
Negative indexing starts from the end; `-1` refers to the last character, which is 'n'.
What does `'hello' in 'hello world'` evaluate to?
Answer: True
The `in` operator returns `True` if the left string is a substring of the right string.
Which string method checks if a string starts with a specified prefix?
Answer: startswith()
`startswith(prefix)` returns `True` if the string begins with the given prefix.
What is the result of `str(42)`?
Answer: '42'
`str()` converts an integer to its string representation, resulting in the string '42'.
What does `'Hello World'.count('l')` return?
Answer: 3
`count()` returns the number of non-overlapping occurrences; 'l' appears 3 times in 'Hello World'.
What is the output of `'abc' * 0`?
Answer: ''
Multiplying a string by 0 produces an empty string because the string is repeated zero times.