In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how to analyze the use of functions in python. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Getting started with python-use of functions
Set up your own function
Enter:
#! / usr/bin/python
# Filename: function1.py
Def sayHello ():
Print ('Hello Worldwide')
# block belonging to the function
# End of function
# call to execute sayHello ()
SayHello () # call the function
SayHello () # call the function again
Output:
Hello World!
Hello World!
Explanation:
Def is followed by the function name, and variables can be added after the function name. In this case, no parameters / variables are set, so there is no need to pass parameters / variables when executing. The contents of the function need to be indented inside the function.
The function does not execute by itself. It needs to be called to execute. A total of 2 calls have been made and 2 Hello World has been output!
Establish a function with parameters
Enter:
#! / usr/bin/python
# Filename: func_param.py
Def printMax (a, b):
If a > b:
Print (a,'is maximum')
Elif a = = b:
Print (a,'is equal to', b)
Else:
Print (b,'is maximum')
# function partial end
# the following is the calling part
PrintMax (3,4)
# directly give literal values
X = 5 y = 7
PrintMax (x, y)
# give variables as arguments
Output:
4 is maximum
7 is maximum
Explanation:
In this example, a function with two parameters is constructed, and a statement with three sets of judgment conditions is constructed inside the function to realize the function of comparing the size of the two parameters.
The parameter value needs to be given when calling.
Summary:
The use of functions with empty arguments, and the use of functions with non-empty arguments. The details of the function need to be fully indented. When calling, you need to give the parameters according to the actual situation of the function and make the call. Multiple functions with the same function name but different arguments can be called at the same time.
The above is how to analyze the use of functions in python. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.