Skip navigation
Functions in Python Functions in Python are blocks of code that perform a specific task.
0:00

Functions in Python Functions in Python are blocks of code that perform a specific task.

Functions in Python Functions in Python are blocks of code that perform a specific task. Instead of writing the same code again and again, you can put it inside a function and just “call” it whenever needed. Think of a function like a machine: you give it some input, it does some work, and then it gives you an output. 👉 | Why use Functions? ♦️ | Helps avoid repeating code. ♦️ | Makes programs easier to read. ♦️ | Keeps code organized. 👉 | How to Define a Function in Python? We use the def keyword: def greet(): print("Hello, welcome to Python!") Here: ♦️ | def → tells Python we’re defining a function. ♦️ | greet → is the function name. ♦️ | Inside, we wrote what the function should do. 👉 | Calling the Function To use (or call) the function, just write its name followed by (): greet() Output: Hello, welcome to Python! ✅ Summary ♦️ | Functions = reusable blocks of code. ♦️ | Defined using def. ♦️ | Run them by calling their name with ().

Comments

Comments from the original post on Instagram

No comments yet