Python - Functions

Published: 07 January 2024
on channel: Learnbatta
56
4

A function is a block of code which only runs when it is called.

why to use function?

Automate repetitive tasks
Allow code reuse
Improve code readability
Clean-up code
Allow easier refactoring

find factorial of a number

def factorial(number):
result = 1
for i in range(1, number+1):
result = result * i
return result
call the function
print(factorial(4))
Output: 24
print(factorial(5))
Output: 120

#python #python3 #function #learnbatta

https://learnbatta.com/course/python/...


On this page of the site you can watch the video online Python - Functions with a duration of hours minute second in good quality, which was uploaded by the user Learnbatta 07 January 2024, share the link with friends and acquaintances, this video has already been watched 56 times on youtube and it was liked by 4 viewers. Enjoy your viewing!