Strings

Concepts

  • The string type str:

  • The minimal string '',

  • Indexing []

  • Slicing [:]

  • Membership: in(), not in())

  • Inmutability property.

  • The string methods:

  • The str.format() method (String_Formattig/index).

  • String traversal

Keywords

# size
     len()
# access and slice
     s[i], s[2:7], s[2:10:2]
# membership
     'a' in s, 'a' not in s, s1 in s,
# string methods
     s.count('a'), s.replace('a', 'A'), s.isalpha(), ...

Examples

Notes

Slides

References

Exercises

String Operations (operators, functions, methods)

Exercises

String traversal using for either over the str or over range(len(str).