Developed with the old boy's education in Python [Article 3]: Python functions, old boy python

Source: Internet
Author: User

Developed with the old boy's education in Python [Article 3]: Python functions, old boy python

Set

Unordered, non-repeated, nested.

Function

Create a function:

1. def Keyword: Create a function

2. Function Name

3 ,()

4. Function body

5. return values

Default return value of the return function in the mail function None common parameter default parameter

Note: To specify a default value for a parameter, the parameter must be placed at the end of the parameter list.

Specify parameter dynamic parameters :*

Note: * by default, all input parameters are placed in the tuples, f1 (* li ).

Dynamic parameters: Dictionary (**)

Note: ** by default, all input parameters are placed in the dictionary, f1 (** dic ).

Universal Parameters

Note: the order of * args and ** kwargs cannot be changed.

Use the format function to guess the output of Dynamic Parameters

 

Note: function parameters pass references.

Global Variables

Note: The global variable must be assigned a value again. You can modify the list or dictionary and cannot assign a value again. Define all global variables in uppercase.

Functions implement login and registration of Three-element operations (three-object operations) lambda expressions built-in functions

Flush:

Readable () to check whether the object is readable, True or False is returned.

Readline () reads only one row of data. When the file size is very large, the memory will not pop up.

Truncate () truncation, data after the pointer is cleared

For loop open file object:

Write the first 10 rows of file 1 to file 2:

Replace a string of the file:

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.