0

What is function in python

QQ And thanks

15th Sep 2021, 1:50 PM
Joey Gastusfon
Joey Gastusfon - avatar
4 Answers
+ 2
Prevents code rewriting
15th Sep 2021, 4:46 PM
Amirreza
Amirreza - avatar
+ 2
Function is a block of code, reusable code that is used to perform a single, related action.
15th Sep 2021, 5:42 PM
Parith (Faree)
Parith (Faree) - avatar
+ 2
Just imagine you have a robot in front of you and you have to give it instructions to a certain goal. You can use the commands "go forwards", "go backwards", "turn right", "turn left". These commands act as functions to instruct the robot. Let's say the goal is right in front of us and we need to go 4 steps forward. Your instruction to the robot would be: go forward() ....go forward() ....go forward() ....go forward() .... Here you called the function go forward 4 times. But this isn't smart. We can define a function to handle these commands: def go_4_steps_forward() go forward() go forward() go forward() go forward() Now we can call the function that we named "go_4_steps_forward" with one single line. This is what makes function so powerful. You can reuse them in your code later on.
15th Sep 2021, 9:20 PM
Max_Mnemo
Max_Mnemo - avatar
+ 1
Generally, function is a work or a operate of some calculations, working steps... etc. I check your account and it looks you didn't start to learn Python. Just start to learn Python and when you come the part of "Functions", you'll able to get it what function is. Happy coding!
15th Sep 2021, 2:04 PM
mesarthim
mesarthim - avatar