Professional Documents
Culture Documents
week 2
PYTHON REFRESHER
Python has many function, but we can also create
Function our own function.
def least_difference(a, b, c):
diff1 = abs(a - b)
In the example, we create a function called
diff2 = abs(b - c) least_difference which has three arguments, a, b, c
diff3 = abs(a - c)
return min(diff1, diff2, diff3) Function is started with ‘def’. Code block after ‘:’
is executed when the function is called
‘return’ is another keyword used in a function. It
define what is the result of the function
Function From the example, we define a function called
def call(who=“Nadya”): ‘call’ which has an argument ‘who’. We also
print(“Helllo,”,who) assign a value “Nadya” for the argument ‘who’.
If we call the function without assigning a value,
#call the function w/o assigning value then the function ‘call’ will have the value of
>>>print(call()) argument ‘who’ as “Nadya”.
“Hello, Nadya”
#call the function with assigning value
>>>print(call(“Budy”))
“Hello, Budy”
LOGIC CONTROL FLOW AND
Python Refresher LOOP
Comparison Operations
result :
Mercury Venus Earth Mars Jupiter Saturn Uranus
Neptune
Range
Range is a function that returns a
row of values.
for i in range(5):
print("Doing important work. i =", i)
While i=0
While will do the loop until the while i < 10:
condition is met print(i, end=' ')
i += 1