Python Functions: Blocks of Code for Reusability

𝘿𝙖𝙮 8/50𝘿𝙖𝙮𝙨𝘾𝙝𝙖𝙡𝙡𝙚𝙣𝙜𝙚 𝙁𝙪𝙣𝙘𝙩𝙞𝙤𝙣𝙨 𝙄𝙣 𝙋𝙮𝙩𝙝𝙤𝙣: A function is a block of code that performs a specific task. 👉 We can use functions as: ✅ reduce code repetition ✅ make code clean ✅ reuse code again and again 👉𝙎𝙮𝙣𝙩𝙖𝙭: def function_name(): #code : def greet(): print("Hello, Welcome to Python!") 𝙏𝙮𝙥𝙚𝙨 𝙤𝙛 𝙁𝙪𝙣𝗰𝙩𝙞𝙤𝙣𝙨 𝙞𝙣 𝙋𝙮𝙩𝙝𝙤𝙣: 🎯 𝘉𝘶𝘭𝘪𝘵 𝘐𝘯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴: These are functions that are already provided by Python. 𝐂𝐨𝐝𝐞: print("Hello") len("Python") type(10) 🎯 𝘜𝘴𝘦𝘳-𝘥𝘦𝘧𝘪𝘯𝘦𝘥 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴: These are functions created by the user. 𝐂𝐨𝐝𝐞: def greet(): print("Hello") greet() 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴 𝘞𝘪𝘵𝘩𝘖𝘶𝘵 𝘗𝘢𝘳𝘢𝘮𝘦𝘵𝘦𝘳𝘴: A function that does not take any input. 𝐂𝐨𝐝𝐞: greet() 𝐨𝐮𝐭𝐩𝐮𝐭: Hello, Welcome to Python! 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘸𝘪𝘵𝘩 𝘗𝘢𝘳𝘢𝘮𝘦𝘵𝘦𝘳: A function that takes input values. 𝐂𝐨𝐝𝐞: def greet(name): print("Hello", name) greet("Durga") greet("Python") 𝐨𝐮𝐭𝐩𝐮𝐭: Hello Durga Hello Python 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘞𝘪𝘵𝘩 𝘙𝘦𝘵𝘶𝘳𝘯 𝘝𝘢𝘭𝘶𝘦: A function that returns a value. 𝐂𝐨𝐝𝐞: def add(a, b): return a + b result = add(10, 20) print("Sum =", result) 𝐨𝐮𝐭𝐩𝐮𝐭: Sum = 30 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘞𝘪𝘵𝘩𝘰𝘶𝘵 𝘙𝘦𝘵𝘶𝘳𝘯 𝘝𝘢𝘭𝘶𝘦: A function that does not return anything. 𝐂𝐨𝐝𝐞: def show(): print("Python") show() #coding #pythonbasics #50dayschallenge #motivation #bvcec #ece

To view or add a comment, sign in

Explore content categories