"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Detailed explanation of Python Day functions: meaning, type and data type

Detailed explanation of Python Day functions: meaning, type and data type

Posted on 2025-04-18
Browse:157
name = input("What is your name?")
print("Welcome to Python", name)

Use text editor to type syntax and save with extension .py and then to run this syntax in desktop page right click and select Open in Terminal

Python Day Functions-Meaning & types, Data type

To run the program enter python3 (file name).py,Then click enter and enter a name.So that program will run.

Input
name = input("What is your name?")
print("Welcome to Python", name)

Output
What is your name?Guru
Welcome to Python Guru

Functions:செயல்கூறு(Actions)
What is function?
Set of instructions for achieving a specific task with a name.
Example:
Watching_Meyyazhagan:
1. Laptop On
2. Netflix
3. Meyyazhagan
4. Play
Now in this above example for watching meyyazhagan movie the set of instructions are to be done like laptop on, open netflix, click meyyazhagan, Then click play button, But for instant we can say watching meyyazhagan which is a name includes all these set of actions.

()-Brackets represent some action is to be done. Inside brackets if anything is specified it is called as arguments or parameters,which is used to perform that function(action).Even without any arguments also a function can be performed.

ex:
eat(food)
sleep()
walk()
cook(rice, water)
swim(dress, pool)
write_exam(hallticket, pen, paper, pencil, scale, rubber, question_paper)

*Supporting Arguments: Comma Separated arguments.

input(),print()-Before brackets what action to be done will be mentioned in this input,print are functions to be performed.

Why function is required?
It is reusable code.No need to mention the full actions again and again we can use just one function.As already said example of watching meyyazhagan contains various actions to be done but we can just say watching_meyyazhagan.

Functions criteria:

  1. Function name should be meaningful.
  2. It should action names not just object name like laptop.
  3. It should not be in numbers.
  4. It should not contain space.
  5. Only "_" special character is allowed, not other special characters.

Types of functions:
predefined-Set of functions which are predefined while creating this language.Ex:input(),print().
Userdefined-set of functions which we can define whenever required.
Ex:

#Function Definition
def calculate(no1,no2):#parameter / argument
    print(no1 no2)
    print(no1-no2)
    print(no1*no2)
    print(no1/no2)

no1 = 120
no2 = 40
calculate(no1,no2) #Function Calling Statement

The above mentioned user defined function can also be done without user defined function "calculate" as following.

no1 = 100
no2 = 5
print(no1 no2)
print(no1-no2)
print(no1*no2)
print(no1/no2)

But the problem is in this every time we have to enter the action to be done. If we have defined function it will be easy to perform by python.

Release Statement This article is reprinted at: https://dev.to/guru_prasanna_ea09e8fcd05/python-day-2-functions-meaning-types-data-type-1ek1?1 If there is any infringement, please contact [email protected] to delete it.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3