Python Interview 1

Source: Internet
Author: User

Gd_sehun
Links: http://www.imooc.com/article/2367
Source: MU-Class Network

1.

Read the code below to write the final value of A0,A1 to an.

A0=Dict(Zip((A,' B ',C,' d ',E),(1,2,3,4,5)))A1=Range(10)A2= [IForIinchA1ifIinchA0]A3= [A0[s]  forsinchA0]A4= [IForIin A1 if I in  A3]a5 ={i:i* i for I in A1 }a6 = [[,i*i  for I in A1  
/span>

2.

What do these two parameters mean: *args , **kwargs ? Why should we use them?

If we are not sure how many arguments we want to pass into the function, or if we want to pass the arguments as lists and tuples in the function, then it will be used *args if we do not know how many keyword parameters to pass into the function, or if we want to pass in the dictionary value as a keyword parameter **kwargs . argsand kwargs These two identifiers are used in a conventional way, and of course you can use *bob and **billy , but that's not quite right.

           

3.

What does the following mean: @classmethod , @staticmethod , @property ?


These are adorners (decorator). An adorner is a special function that either accepts a function as an input parameter and returns a function that accepts a class as an input parameter and returns a class. The @ tag is a syntactic sugar (syntactic sugar) that allows you to decorate a target object in a simple, easy-to-read manner.

@classmethod, @staticmethod, @property The objects used for these three adorners are functions defined in a class. The following examples show how they

4.

random = [Random.random () for I in range (100000)]

Produces a random number within (0-1), altogether 100,000

5.

Lambda functions

Lambda expressions, which are usually used when a function is needed, but do not want to bother to name a function, that is, an anonymous function

Lambda function: The primary purpose is to point a short callback function

Lambda [arguments]:expression

>>> A=lambdax,y:x+y

>>> A (3,11)

6.

RE module; Regular Expression Module

           

 

 

/span>

 

           



Python Interview 1

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.