3.6: Chapter Summary
( \newcommand{\kernel}{\mathrm{null}\,}\)
Highlights from this chapter include:
- A string is a sequence of values that represents Unicode code points.
- An index refers to the position of a value in a sequence (string, list, tuple).
- Positive indexes range from 0 to length–1. Negative indexes range from –1 to –length.
- F-strings are a convenient way to print multiple outputs and format integers and floats.
- Variables refer to objects. Memory diagrams are useful for drawing variables and objects.
- A list object can be used to refer to multiple objects, by index, using the same variable.
- A tuple is similar to a list, but uses parentheses and cannot be changed once created.
Code | Description |
---|---|
ord(c)
|
Gets an integer representing the Unicode code point of a character. |
chr(i)
|
Converts a Unicode code point (integer) into a One-character string. |
'\n'
|
Escape sequence for the newline character. |
'\t'
|
Escape sequence for the tab character. |
f"{number:.02d}"
|
Creates a string by formatting an integer to be at least two digits. |
f"{number:.2f}"
|
Creates a string by formatting a float to have two decimal places. |
id(object)
|
Gets the identity (memory location) of an object. |
type(object)
|
Gets the type (class name) of an object. |
my_list = ["a", "b", "c"]
|
Creates a list of three strings. |
my_tuple = ("a", "b", "c")
|
Creates a tuple of three strings. |
my_list[0]
|
Gets the first element |
my_tuple[-1]
|
Gets the last element |
Table 3.5 Chapter 3 reference.