Skip to content

Chapter 3 - Strings and print

Introduction

Strings

Common string manipulation operations

Operation Description
len(s) Length of string
s[0], s[1], s[-1] Index into the string.
Just like with Lists, negative indices can be used
to index from end of string.
s[:3] Grab the part of string from start upto but not including index 3
s[3:] Grab the part of string from index 3 to the end
s[2:5] + k[3:5] Strings can be concatenated using the + operator.
This example shows combining slicing and concatenation.

Concat using .join()

Split and strip

Case sensitivity

Talk about how I always compare two strings using .lower()

  • concat ... + versus .join
  • split
  • strip, rstrip, lstrip
  • lower, upper, title

String matching and regular expressions

str.find() common regex patterns

Print

Pretty printing lists and dictionaries

Formatting strings

Tabulating data