EXTRAS FROM QUIZ QUESTIONS Flashcards
when does a result or print return something with quotation marks?
returns quotation marks ONLY for strings, and prints NEVER return with quotations unless directly after a \
OR if you use
repr(string) in the print
what does
x = ‘hello world’
repr(x)
do?
’ ‘hello world’ ‘
^two quotation marks on each side, jupyter notebooks makes it a string and repr makes it also
will this compile?
str = ‘cat’
str[0] = ‘dog’
no, as you are editing the string on a character basis. you COULD change the string as a whole, like:
str = str + ‘dog’
but you cant edit the string itself (immutable)
what does repr do?
keeps/returns the string surrounded by single quotation marks
print(repr(“bill”))
prints
‘bill’
what does end=’…’, sep=’ ‘ mean?
instead of printing a new line, the end of the print will be a …, and the sep means when youre printing multiple things it is separated by the specific thing = to set
ex.
print(‘bruh’, ‘i’, ‘cant’, end = ‘…’, sep=’bill’)
would print
bruhbillibillcantbill…
what does .title() do?
capitalizes first letter and lowercases other letters of each word separated by a space
how to capitalize m in mark?
‘mark’.title()
what does the floor function do?
MATH MODULE FUNCTION
returns a float lowered to the nearest whole number (-3.5——>-4.0, 3.5—->3.0)
true/false: input statements from users are printed IMMEDIATELZY AFTER the input prompt, with no spaces automatically added
true true true
make a condition that returns false when a string does NOT equal another string
if not(x == y):
does != work on python?
yes, but the other stuff from java like && || just straight dont work.
is round part of the math class?
nah
what will this print:
i = 1
if i ==1, 2, 3:
print(“YES”)
error, you cant do equals like that, must put “i == 1 or i == 2 or i ==3”