A preliminary knowledge of Python Day9 note function

Source: Internet
Author: User

1. Function: Encapsulate a function

|def My_len (formal parameter): DEF declaration defines a function My_len function name naming rules same variable

|
| ······
|          ······ -> function body, write code to achieve the desired function
|          ······ Using formal parameters in the body of the function to make internal modifications to external mutable data type variables
| ······
| return x, which is returned when you encounter return, does not perform the following
| ······
|
|my_len (argument)-here executes the function, that is, the calling function needs to declare the definition before calling the format: function name + ()

To pass the parameter:

My_print (' 123 ', ' abc ', ' Satan ') positional arguments, i.e., based on (concrete argument value) one by one corresponding to the parameters passed to the parameter

My_print (b= ' 123 ', c= ' abc ', A= ' Satan ') key-pass argument, that is, the argument is passed (parameter name)
My_print (' 123 ', b= ' abc ', c= ' Satan ') mixed, that is, (the key argument) must be all at the back of (the positional argument).
Default parameters:

def my_print (a,b,c=none,d={}) the formal parameters with default values must all be behind formal parameters with no default values.

On the inside of a function, the difference between a reference to an external (variable of variable data type list,dict) and a reference to an external (variable of immutable data type, such as INT,STR):


Reference: https://www.cnblogs.com/kayb/p/7194006.html

(You cannot change the direction of a global variable.) )

Again, if I is {}: This comparison is the memory address that is compared to the small data pool. Variable data types such as dictionaries, lists, and no small data pools.


A preliminary knowledge of Python Day9 note function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.