In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how python creates functions". The content is simple and easy to understand. It is clearly organized. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn "how python creates functions".
One: Create a function:
A function can be called (possibly including arguments, i.e. values enclosed in parentheses), performs some behavior and returns a value. In general, the built-in callable function can be used to determine whether a function is callable (callable is not available in Python 3.x):
Function definition:
Format: def Function Name (Parameter):
return (statement)
def hello(name):
return ('hello'+ name)
>>> def hello(name):
... return('ilove'+name)
>>> print(hello('ly'))
ilovely
>>>
>>> def fibs(num):
... result=[0,1]
... for i in range(num-2):
... result.append(result[-2]+result[-1])
... return(result)
...
>>> fibs(10)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
>>>
II. Record function: add remarks
For example:
>>> def fibs(num):
... 'itis a defin' //docstring
... result=[0,1]
... for i in range(num-2):
... result.append(result[-2]+result[-1])
... return(result)
...
>>>
>>> fibs(10)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
>>>
Python function can return no value (return is null, return is None)
IV. Parameters:
The parameters that follow the function are generally called formal parameters, and the values provided when the function is called are the actual parameters. A parameter is just a variable. Assigning new values to parameters inside a function does not change the values of external variables, and similarly, rebinding parameters inside a function does not affect variables outside the function.
Parameters stored in local scope
That's all for "how python creates functions", thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.