Character strings
The string as an indexed sequence of characters: length, access, slicing, concatenation, immutability, traversal, lexicographic order and common operations (case, search, replacement, splitting, joining).
- 26 cards
- 6 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The numbers
- Scenarios
- Understand
A few cards from the deck
String: what is it?
Show the answer
An ordered sequence of characters, identified by their position like the cells of an array, used to represent text.
len('hello')is 5,'hello'[0]is'h'and'hello'[-1]is'o'. A single character is a string of length 1 in Python.What does this program print?
```python
s = "informatique"
print(s[2:7:2])`fraformaomtnom
Show the answer
fraThe indices taken are 2, 4 and 6:
f,r,a(7 is excluded).formaignores the step,omtstarts at index 3,nomat index 1.Joining two strings end to end is called …; in Python, it is written with the … operator.
Show the answer
Joining two strings end to end is called concatenation; in Python, it is written with the + operator.
'ab' + 'cd'gives'abcd', but'ab' + 1raises aTypeError: convert withstr(1). The*operator repeats:'ab' * 3gives'ababab'.Slice: what is it?
Show the answer
A contiguous part of a string, given by a start index, an excluded end index and, optionally, a step.
s[2:5]takes indices 2, 3 and 4. An omitted bound goes all the way:s[:3]for the first three characters,s[-3:]for the last three,s[::-1]for the reversed string.