Functions of Python

Source: Internet
Author: User
Tags readable

1 "Function:
1> definitions, keywords and calls:

The return value of the 2> function:

General parameters of the 3> function:

Default parameters for the 4> function: The default parameter must be placed at the end;


Parameters can be specified:

5> Dynamic Parameters:
*: Converts the passed-in parameter to a tuple;

* *: Converts the passed in parameter to a dictionary:


*,**: You can process incoming parameters into tuples and dictionaries at the same time, the parameters must first specify *, then specify * *;


The parameter variables passed in represent tuples or dictionaries:

2. Format strings using dynamic parameters:


3 lambda expression: simple representation of simple function;


4 "Python built-in functions:
Common built-in functions:

1>abs (): absolute value;
2>all (): The element that will loop input, only if all elements are true will output true, otherwise false;


3>any (): As long as one of them is true, it is true;

4>ascii (): Equivalent to int.__repr__, returns the ASCII code of the input value;
5>bin (): The input parameters can be converted into binary digits;

6>bytearray (): can convert input elements into byte arrays, one kanji three bytes; (Not supported in 2)

p = ByteArray (' Chei Huiwei ', encoding=' Utf-8 ')
        Print (p)

7>callable (): The variable is followed by parentheses whether it is executable;


8>CHR (): converts ASCII to characters;
Ord (): Converts characters into ASCII code;


9>classmethod (): Object-oriented use;
10>compile (): A string can be compiled into Python code;
11>delattr (): used when reflecting;
12>enumerate (): Adds a column of self-increment elements to the loop output;

13>eval ():
>>> eval ("6*8")
14>filter (): Filters the elements in the sequence and finally gets the sequence that matches the conditions;

15> map (): Iterates through the sequence, operates on each element of the sequence, and finally acquires a new sequence;

17>frozenset (): cannot be added with the modified collection;
18>globals (): all currently available variables;
19>hex (): converted to 16 binary;
20>max (): Take the maximum value;
Max (11,22,33,44)
21>oct (): converted to octal;
22>range ():


23>reversed (): invert;
24>round (): rounds the input numbers;
25>zip (): Re-group two lists, tuples or dictionaries;

26>open (): Used to manipulate files;
R: read-only mode;
W: write-only mode; (unreadable, not present, created, delete content exists)
A: Append mode (readable, non-existent, create, only append content if present)
+: Indicates that you can read and write files simultaneously:
R+: Can read and write files, (readable, writable, can be appended)
w+: Write and read;
A +: with A;
U: indicates that \ r \ n can be automatically converted to \ n (in conjunction with R or r+ mode) when reading
B: Represents the processing of binary files;

Read two bytes:


Read Chinese characters, a Chinese character three bytes (3 in the character read, a Chinese character and a letter is a character):

27>tell (): The position where the pointer can be output;


28>seek (): You can specify where you want the pointer to jump, specifying the current pointer position;

29>read (): Specifies the number of characters to read;
30>truncate (): Specify the current pointer position, and then modify the original file so that the original file only the current pointer before the Rrong capacity (test.log:123456);


31>json.loads (): A dictionary-like string can be converted to a dictionary (3 can be, 2 does not);



Functions of Python

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: 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.