Strings and Bytes

  • Single and multi-line string quoting
  • Adjacent string literal concatenation
  • Universal newlines
  • Escapes sequences for control characters
  • Raw strings suppress the escaping mechanism
  • Convert other types using
    • str()
  • Python 3 source encoding is in UTF-8
  • str (String) is a sequence of Unicode codepoints
  • bytes is a sequence of bytes
  • Convert str to bytes
    • encode()
  • Convert bytes to str
    • decode()


numbers = [1,2,3,4]
# look a list!
  • Lists are a sequences of objects
  • List literals are made by using square brackets “[]” and items are seperated by commas “,”
  • List indexing is zero based, you can access object by their number
    • numbers[0]
  • Add more to lists
    • append()


dictionary = {Key1: Value1, Key2: Value2}
# look a dictionary!
  • Dictionaries associate keys with values
  • You make dicts using curly braces
  • Key-value pairs are seperated by commas, with colon in between each key and value.
  • You can access certain values by:
    • dictionary['Key1']
    • OUTPUT: Value1