Chapter 4 - For loops, Strings, and Tuples Flashcards
an ordered list of things
a sequence
All sequences are made up of …..
elements
a sequence in which each element is one character
a string
(start, stop, step)
range(), the end point is not included (if it’s 50, 49 is the last number included)
find message length with…
a sequence’s length is equal to the number of elements it has.
len()
differences between elements and characters
a space is an element but not a character
going through a sequence one character at a time
sequential access
direct access
random access
you can specify a position in a sequence and get the element at that position
indexing
[-1] negative index number
last character
high = len(word) low = -len(word)
What index positions will this produce if word = “index”
position = random.randrange(low, high)
-5, -4, -3, -2, -1, 0, 1, 2, 3, 4
In other words: it will produce a random number from and including the low end point, up to, but NOT including the high end point.
the inability of strings to be changed
string immutability
A variable written in ALL CAPS by convention
- more readible
- used for variable meant to be unchaning
constant
a section of elements (part of a sequence)
a slice
start = None
placeholder, evaluates to False