Python Functions
Index
· What is a function in python?
o Syntax of Function
o Example of a function
o How to call a function in python?
· Docstring
· The return statement
o Syntax of return
o Example of return
· How Function works in python?
· Scope and Lifetime of variable
· Types of Functions
What works in Python?
Python, work is a group of private sector executives.
Help with exercise to break into smaller and similar programs.
Syntax of Function
Docstring
The return statement
Syntax of return
return [expression_list]
How to work in Python mode?
As our program has grown a lot, the job creates a more manageable system.
def function_name(parameters):
"""docstring"""
statement(s)
In addition, repairs are avoided and make them recyclable.
The word
The definition of the definition above is shown in the following sections.
1. The key word of the TKR is a sign of the beginning of a leader.
2. Name of activity to identify inappropriately. The name of the job is the same as Python's writings.
3. A guide (a reason) used for the cost of performance. They prefer.
4. Time (:) to show the end of the leader.
5. Good writing materials (message) to explain what works.
6. Python One or more relationships that relate to physical activity. The proof must contain the same level of bleeding (usually 4 places).
7. A clear choice to return to work value.
Examples of activities:
def greet(name):
"""This function greets to
the person passed in as
parameter"""
print("Hello, " + name + ". Good morning!")
How to call Python activities?
When we have a specific task, we can call other programs or even call Python. To call the action you have to write the name of the job, according to the boundaries.
Syntax:
>>> greet('Sai')
Hello, Sai. Good morning!
The first presidential chain of chain of documents and chains of chains. It is used to describe a few words, what's working at the wedding.
While selecting, the documents are a good program. Apart from where to find it was the first night, always write your number.
In the first example, we have alerted the leader immediately. We often use three-digit documents that can be extended up to several lines. This cord is available to us as __doc__ the features of the job.
For example:
>>> print(greet.__doc__)
This function greets
the person passed into the
name parameter
Try to keep the bottom of the rubbish bin, Python watching out.
After this, it is used to leave the work and return to the place known.
This statement can contain an expression which gets evaluated and the value is returned. If there is no expression in the statement or the return statement itself is not present inside a function, then the function will return the None object.
For example:
>>> print(greet("May"))
Hello, May. Good morning!
None
How Function works in python?
Life insurance and variables:
The size of a part of the program depends on the known changes. Articles and trends are defined in an unprecedented act. Therefore, they have a place to live.
A period of change in your life using a set of variables. Changing the life of the task during the operation is carried out.
When it is broken, let's go back to the action. Therefore, the action does not tell the cost of the old call.
Below is an example showing the effectiveness of the work.
E
def my_func():
x = 10
print("Value inside function:",x)
x = 20
my_func()
print("Value outside function:",x)
Here, we can see that the value x is initially 20. Although mi_func () works x value of up to 10, it does not affect external activities.
This is due to a variable variable variable x (different performance) from outside. Although they have the same name, which is two different variables, with different methods.
On the other hand, external variables for the functions appear inside. They have an international level. We can read about the value of this job, but we can not change it (in writing). To evaluate the value of non-functional values, it must be expressed as an international variable using the keyword.
Types of Functions:
Basically, we can divide up two types of the following activities:
1. Build up activities - jobs built for Python.
2. Operations defined in the user - activity defined in the user.
Watch out for this example to learn:
• Get HCF or GCD
• Search mcm
• Create a simple calculator
To getting expect level training for Python training in your Location – Python training in Chennai | Python training in Bangalore | Python training in Pune | Python training in Velachery | Python training in Tambaram | Python training in Marathahalli | Python training in btm.| Python Online Training.
Comments
Post a Comment