math operations Flashcards
sep=” “
space between two words
end=”\n”
end of line
int + string
string / integer
unsupported operand type– type error
string * 2
stringstring
\n
next line
"
to escape quotation mark
sentense.replace
will replace a word “ I “ or a character
f string
string format
(x / y)
exact division answer
x//y
only whole number
x%y
remainder
x += 3
x = x + 3
x -= 3
x = x - 3
x /= 3
x = x / 3
x %= 3
x = x % 3
x //= 3
x = x // 3
x **= 3
x = x ** 3
is
Returns True if both variables are the same object
x is y
in
Returns True if a sequence with the specified value is present in the object
x in y
thislist = [“apple”, “banana”, “cherry”, “orange”, “kiwi”, “melon”, “mango”]
print(thislist[:4])
This example returns the items from the beginning to, but NOT including, “kiwi”:
[‘apple’, ‘banana’, ‘cherry’, ‘orange’]
This example returns the items from “cherry” to the end:
thislist = [“apple”, “banana”, “cherry”, “orange”, “kiwi”, “melon”, “mango”]
print(thislist[2:])
This example returns the items from “cherry” to the end:
[‘cherry’, ‘orange’, ‘kiwi’, ‘melon’, ‘mango’]
thislist = [“apple”, “banana”, “cherry”, “orange”, “kiwi”, “melon”, “mango”]
print(thislist[-4:-1])
This example returns the items from “orange” (-4) to, but NOT including “mango” (-1):
[‘orange’, ‘kiwi’, ‘melon’]