Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Python function

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to use the Python function". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

A mathematical function is a correspondence in which there is a unique output when an input is given. Functions in programming languages have the same meaning, but they are also different. A function is a statement with a name that you can use over and over again when needed. It may require input, and it may return output.

Let's take a real scene: we went to the restaurant and ordered with the waiter, and after a while, the waiter brought up the prepared food. The kitchen of the dining room can be regarded as a function, and the menu we order is the parameter to this function; the process of cooking in the kitchen is the execution of this function; the finished dish is to return the result and return to our table.

We have used built-in functions in python before, such as input and range.

Take range (1BI 10) as an example, range is the name of this function, and the 1 and 10 in parentheses are the parameters required by range. It has a return result, which is a sequence from 1 to 9.

Let's take a look at input (). It's not in parentheses, which means we didn't give a parameter. During the execution of the function, we need to enter a value from the console. The return result of the function is what we entered.

PS:range can also accept 1 or 3 parameters, and input can accept 1 string parameter. You can wait for me to talk about it later, or consult the relevant materials for details.

If we want to write a function ourselves, we need to define it. The keyword in python is called def (abbreviation for define), and the format is as follows:

Def sayHello ():

Print 'hello worldview'

SayHello is the name of the function, followed by arguments in parentheses, which are not available here, indicating that no arguments are needed. But you can't do without parentheses and followed by colons. The following indented block of code is the content of the entire function, called the function body.

Then we call this function:

SayHello ()

Get and directly execute print 'hello worldview' Same result.

This is the end of the content of "how to use Python function". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report