Python study notes-day6- continuation of the function [Chinese character to pinyin module, function returns multiple values, anonymous function, list generation, generator generator, ternary operator]

Continue to talk about the follow-up knowledge points of functions, mainly functions returning multiple values, anonymous functions, and ternary operators, which are relatively small knowledge points.

1. The use of Chinese characters to pinyin mode

1. Install the module

#install xpinyin

2. If you use

result:

 

 

Second, the function returns multiple values

1. Python functions can return multiple results at the same time,

#If the function returns multiple values, it will put these values ​​in a tuple

2. res1, res2, res3 = say() #You can also use three values ​​to receive

 

 

 3. Anonymous functions

1. Definition

#Anonymous function, the function of this function is very simple, only use 
#lambda once, use lambda to realize



2. The meaning of lambda expression

 

 

4. List Compilation

1. The function of list comprehension is the same as that of loop, but it does not need to use loop code

 

2. Example usage of list comprehension

 

 Five, generator generator

The list comprehension of the fourth item is for list, but it is also possible to use tuple, but the returned object is a generator generator.

 1. Example

 

2. The essence of generator generator

 

 3. The generator can only access elements one down, the method:

 

result:

lst2.__next__() #1

 

6. Ternary operator

1. Ternary operator function

The same function as if else, used to judge

 

2. Example:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324611395&siteId=291194637