Home > Backend Development > Python Tutorial > Python Day Functions-Meaning & types, Data type

Python Day Functions-Meaning & types, Data type

Susan Sarandon
Release: 2024-11-25 20:28:16
Original
243 people have browsed it
name = input("What is your name?")
print("Welcome to Python", name)
Copy after login

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
Copy after login

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

Copy after login

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)
Copy after login

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.

The above is the detailed content of Python Day Functions-Meaning & types, Data type. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template