Functions in Python_1
Functions in Python_1
(Functions in Python)
• For Loop
• While Loop
• Nested Loops
Contents
• Exercise on loop and decision making
• Introduction to Function
• Syntax of Function
Functions
Linear Binary
Function
Built-in functions: The standard functions that are provided by
python.
def prime(n):
for x in range(2, n):
if n % x == 0:
break
else:
# loop fell through without finding a factor
print(n, 'is a prime number')
Syntax of Function
def functionName(paramList):
function_suite (Code)
return [Expression/Value/Variable]
• Function name (functionName) is a valid identifier.
• Valid Function names: IntegerSum, _FloatSum23, printSum
• Invalid Function names: 23IntegerSum, $FloatSum23,
print&$Sum
for x in range( 1, 11 ):
print (square(x))
Exercises
• Syntax of Function