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

The definition of Python basic knowledge Point function

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "the definition of Python basic knowledge point 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!

Simple function

Function: encapsulates a block of code that can be repeatedly called for execution. A large amount of code can be reused through this code block.

The use of the function involves two steps:

Define functions-encapsulate independent functions

Call function-enjoy the result of encapsulation

Function, when developing a program, using function can improve the efficiency of writing and the reuse of code.

Definition of a function declares a function

Def: a keyword for a function, which is an abbreviation for define

Function name: the name of the function, and then the function is called according to the function name. The function name should be able to express the function of encapsulating the code of the function.

Arg: the argument parameter

Function body: a series of logical calculations are carried out in the function, such as sending e-mail, calculating the maximum number in 11 Magne22, 38, 888, etc.

The naming of function names should conform to the naming rules of identifiers.

Can consist of letters, underscores, and numbers

Cannot start with a number

Cannot have the same name as the keyword

Def is the keyword that declares the function and must be lowercase

Since a function is usually defined to implement a function, we usually name the function as a verb, such as get_sum

Call function

Example: using a function to find the maximum of two numbers

Calling the function is very simple, and the call to the function can be completed through the function name ().

Details

Can I put the function call above the function definition?

I can't!

Because before calling a function with a function name, you must make sure that Python already knows the existence of the function.

Otherwise, the console will prompt NameError: name'f'is not defined (name error: F the name is not defined)

This is the end of the definition of Python basic knowledge point function. Thank you for your 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: 266

*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