Python Flashcards
modulus operator %
- The operands can be either integers or floats.
-finds the remainder or signed remainder after the division of one number by another.
ex: 13%5=3
// floor division
will divide the first argument by the second and round the result down to the nearest whole number
syntax for a to the power of b
a**b
print(False or False or False or True)
how does this expression evaluate?
True - or operator needs only one to be true
how do we check to see if a is divisible by b?
a%b==0
what is the outcome of
print(2>3 and 3<=7) ?
False and True
how do we write multi-line comments?
””” (begin and end with 3 double quotes)
‘’’ (begin and end with 3 single quotes
for i in s
loop syntax…what is i?
i is the variable that will store the elements of the sequence one by one
what is a continue statement?
a loop control statement that forces to execute the next iteration of the loop while skipping the rest of the code inside the loop for the current iteration only.
ex:
for var in “Geeksforgeeks”:
if var == “e”:
continue
print(var)
output will be Gksforgks, every e is skipped
what is range expression syntax?
range(begin, end, intervals)
where begin = the starting number. default is 0
end = one MORE than the number you want to end on
intervals = the intervals at which we want selected along the number line (range)
what is the simplest way we can express a range?
range(integer), which will give us 0 thru the number BEFROE the integer in parentheses
how do we express a range that we want to iterate 5 times?
range(0, 6)
what is the difference between a while loop and a for loop?
a FOR LOOP used to iterate over a sequence of items. will execute a block of statements for each item in the sequence.
a WHILE LOOP is used to repeatedly execute a block of statements while a condition is true. The loop will continue to run as long as the condition remains true.
what is a factorial?
he product of all positive integers less than or equal to a given positive integer and denoted by that integer and an exclamation point. Thus, factorial seven is written 7!, meaning 1 × 2 × 3 × 4 × 5 × 6 × 7