Chapter 6: Strings Flashcards
A variable used to count something, usually initialized to zero and then incremented.
counter
A string with no characters and length 0, represented by two quotation marks.
empty string
A boolean variable used to indicate whether a condition is true or false.
flag
A statement that calls a method.
invocation
The property of a sequence whose items cannot be assigned.
immutable
An integer value used to select an item in a sequence, such as a character in a string.
index
One of the values in a sequence.
item
A function that is associated with an object and called using dot notation.
eg. string.upper()
method
Something a variable can refer to. For now, you can use it and “value” interchangeably.
object
A pattern of traversal that stops when it finds what it is looking for.
search
An ordered set; that is, a set of values where each value is identified by an integer index.
sequence
A part of a string specified by a range of indices.
slice
To iterate through the items in a sequence, performing a similar operation on each.
traverse
Contains both data (the actual string itself) and methods, which are effectively functions that are built into it and are available to any instance of it.
object
boolean operator that takes two strings and returns True if the first appears as a substring in the second
in
eg. ‘a’ in ‘banana’
function that lists object methods
dir()
string method that makes everything uppercase
.upper()
string method that makes everything lowercase
.lower()
string method that makes first letter uppercase
.capitalize()
string method that searches for the position of one string within another. Returns index value
.find(string, starting index)
string method that removes whitespace or substring argument from both ends
.strip()
.strip(substring)
string method that returns True or False if substring matches beginning of string
argument must match case
.startswith(string)
Allows Python expressions to be used within string literals. Accomplished by prepending an f to the string literal and enclosing expressions in curly braces {}
formatted string literals / f-string
eg. camels = 42
f’I have {camels} camels’ = ‘I have 42 camels’
function to get more information about a string method
help()
eg. help(string.method)
x%=1
gives remainder of x divided by value each loop. Doesn’t update variable after first loop
string method that removes whitespace or substring argument from right side
.rstrip(string)
string method that removes whitespace or substring argument from left side
.lstrip(string)
string comparison order
CAPITAL < lowercase
The binding of data and functions (or behavior)
encapsulation
%s
string format operator
s = ‘What… is your favourite colour? %s. Go on. Off you go.’ %(input())
%d
decimal format operator