Lesson 21 of 34

Functions: உங்கள் சொந்த கட்டளைகள்Functions: Your Own Commands

8 min 25 XP

ஒரே code-ஐ பல இடங்களில் திரும்பத் திரும்ப எழுதுகிறீர்களா? அதை ஒரு function-ஆக்குங்கள். def என்று தொடங்கி, பெயர், ( ), : எழுதி, உள்ளே indent செய்து code எழுதுங்கள்.

Writing the same code again and again? Make it a function. Start with def, then a name, ( ) and :, and indent the code inside.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

( ) உள்ளே parameters கொடுக்கலாம். function-ஐ அழைக்கும் போது கொடுக்கும் மதிப்புகள் (arguments) அவற்றில் வந்து சேரும்.

Put parameters inside ( ). The values you pass when calling the function (arguments) arrive in them.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

function-ஐ வரையறுப்பது (def) மட்டும் அதை இயக்காது. அதை அழைக்க (call) வேண்டும்: greet(...)

Defining a function (def) doesn't run it. You have to call it: greet(...)

Challenge

+25 XP

greet(name) என்ற function எழுதுங்கள். அது "Vanakkam, <name>!" என்று print செய்ய வேண்டும். பிறகு greet("Arun") மற்றும் greet("Priya") என அழையுங்கள்.

Write a function greet(name) that prints "Vanakkam, <name>!". Then call greet("Arun") and greet("Priya").

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.