Home Computer Tutorials Troubleshooting Basic knowledge of computer functions?

Basic knowledge of computer functions?

Jun 01, 2024 am 09:55 AM

Do you want to understand the basics of computer functions and lay a solid foundation for your programming journey? PHP editor Apple brings you a comprehensive guide, providing clear and easy-to-understand explanations, covering basic concepts, function types and usage scenarios. Come explore this article, master the essence of computer functions, and unlock new dimensions of programming skills!

Basic knowledge of computer functions?

1. Function definition, function name, function body, and definition syntax for calling the

function:

def function name ( ):

Function body

Call of function: Use the function name to call the function, written as: function name(), at this time the function body will be executed

2. Function Return

After executing the function, you can use return to return the result to the function name ().

The use of return in functions:

1) When the function encounters return, the function ends and execution will no longer continue.

2) Give the function caller (function name + ()) an access result

3. Parameters of the function

Parameters, the function specifies a specific one when calling The value of the variable.

def Function name (parameter list):

Function body

Function name (parameter)

1)Formal parameter

The variables written at the position where the function is declared are called formal parameters. They are complete in form but the actual parameters must be given when calling.

2) Actual parameters

are passed to the function when the function is called. The value is called the actual parameter

3) Parameter passing

The process of passing the actual parameters to the formal parameters when passing information to the function is called parameter passing.

4-1) Positional parameters

means that when passing parameters to a function, values ​​are passed in order

4-2)Default parameters

Definition: When writing a function, you directly pass the default value to the parameter. When the function is called, the default parameter already has a value, so there is no need to pass a value.

Function: The biggest benefit is to reduce the difficulty of calling functions.

def power(m, n=3):

result=1

while n>0:

n=n-1

result=result*m

return result

# Call the function and output the result

print(power(4))

Set default parameters There are two points to note:

First: the required parameters come first and the default parameters come last, otherwise the python interpreter will report an error.

Second: The default parameters must point to immutable objects! Point to immutable object! Point to immutable object!

(Note: Strings, numbers, and tuples in python can all be regarded as objects.)

Why should we design immutable objects like str and None? Because once an immutable object is created, the data inside the object cannot be modified, which reduces errors caused by modifying data. In addition, since the object does not change, there is no need to lock the object when reading it simultaneously in a multi-tasking environment, and there is no problem at all when reading it at the same time. When we write a program, if we can design an immutable object, then try to design it as an immutable object

4-3) Keyword parameter

Definition: Variable parameters allow you to pass in 0 or any number of parameters. These variable parameters are automatically assembled into a tuple when the function is called.

The keyword parameters allow you to pass in 0 or any number of parameters containing parameter names. These keyword parameters are automatically assembled into a dict inside the function. When calling a function, you can only pass in the required parameters:

Function: Extend the functionality of the function

Features: **kw

Classification of parameters:

From the perspective of actual parameters:

1. Positional parameters assign values ​​to formal parameters according to their positions

2. Keyword parameters pass parameters to functions according to the naming of formal parameters

3. Mixed use: write positional parameters first, then write keyword parameters

Standing in the formal parameter supervision:

1. Positional parameters

2. If the default value parameter is given Just get a value. If you don’t give a value, use the default value

The above is the detailed content of Basic knowledge of computer functions?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
How to fix KB5055523 fails to install in Windows 11? How to fix KB5055523 fails to install in Windows 11? Apr 10, 2025 pm 12:02 PM

KB5055523 update is a cumulative update for Windows 11 version 24H2, released by Microsoft on April 8, 2025, as part of the monthly Patch Tuesday cycle, to offe

How to fix KB5055518 fails to install in Windows 10? How to fix KB5055518 fails to install in Windows 10? Apr 10, 2025 pm 12:01 PM

Windows update failures are not uncommon, and most users have to struggle with them, most often becoming frustrated when systems fail to install critical patche

How to fix KB5055612 fails to install in Windows 10? How to fix KB5055612 fails to install in Windows 10? Apr 15, 2025 pm 10:00 PM

Windows updates are a critical part of keeping the operating system stable, secure, and compatible with new software or hardware. They are issued on a regular b

Worked! Fix The Elder Scrolls IV: Oblivion Remastered Crashing Worked! Fix The Elder Scrolls IV: Oblivion Remastered Crashing Apr 24, 2025 pm 08:06 PM

Troubleshooting The Elder Scrolls IV: Oblivion Remastered Launch and Performance Issues Experiencing crashes, black screens, or loading problems with The Elder Scrolls IV: Oblivion Remastered? This guide provides solutions to common technical issues.

Clair Obscur Expedition 33 Controller Not Working on PC: Fixed Clair Obscur Expedition 33 Controller Not Working on PC: Fixed Apr 25, 2025 pm 06:01 PM

Solve the problem of failure of the PC version of "Clair Obscur: Expedition 33" Have you also encountered the problem that the PC version of the "Clair Obscur: Expedition 33" controller does not work properly? Don't worry, you are not alone! This article will provide you with a variety of effective solutions. "Clair Obscur: Expedition 33" has been launched on PlayStation 5, Windows and Xbox Series X/S platforms. This game is an engaging turn-based RPG that emphasizes precise timing. Its uniqueness is the perfect blend of strategic and rapid response. Smooth operation

How to fix KB5055528 fails to install in Windows 11? How to fix KB5055528 fails to install in Windows 11? Apr 10, 2025 pm 12:00 PM

Windows updates are essential to keep your system up to date, secure, and efficient, adding security patches, bug fixes, and new functionality for Windows 11 us

Clair Obscur: Expedition 33 UE-Sandfall Game Crash? 3 Ways! Clair Obscur: Expedition 33 UE-Sandfall Game Crash? 3 Ways! Apr 25, 2025 pm 08:02 PM

Solve the UE-Sandfall game crash problem in "Clair Obscur: Expedition 33" "Clair Obscur: Expedition 33" has been widely expected by players after its release, but many players encountered the error of UE-Sandfall crashing and closing when starting the game. This article provides three solutions to help you smooth the game. Method 1: Change the startup options Change the Steam startup options to adjust game performance and graphics settings. Try setting the startup option to "-dx11". Step 1: Open the Steam library, find the game, and right-click to select "Properties". Step 2: Under the General tab, find the Startup Options section.

Windows 11 KB5055528: What's New & What if It Fails to Install Windows 11 KB5055528: What's New & What if It Fails to Install Apr 16, 2025 pm 08:09 PM

Windows 11 KB5055528 (released on April 8, 2025) Update detailed explanation and troubleshooting For Windows 11 23H2 users, Microsoft released the KB5055528 update on April 8, 2025. This article describes the improvements to this update and provides a solution to the installation failure. KB5055528 update content: This update brings many improvements and new features to Windows 11 23H2 users: File Explorer: Improved text scaling and improved accessibility to the file opening/save dialog and copy dialog. Settings page: Added "Top Card" function to quickly view processor, memory, storage and G

See all articles