One week face questions python Summary: Tuesday

23, lambda functions implemented by multiplying the two numbers?

lambda [arg1 [,arg2,.....argn]]:expression

 

24, according to the dictionary from small to large bond

 

25, the number of library collections using the statistical method of Counter string for each word appears "kjalfj; ldsjafl; hdsllfdhg; lahfbl; hl; ahlf; h"

 

26, the string a = "not 404 found Zhang Shenzhen 99", each word is a space intermediate, with a regular alphanumeric filtered off, the final output "San Shenzhen"

Incidentally paste matching decimal code:

\d+\.\d+

 

27, filter () function to obtain a list of all of the odd and the new list structure, a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

filter () function is used to filter sequences, filtered ineligible element returns a list of qualified new elements. This function receives two parameters, as a function of a first, a second sequence, each element of the sequence as an argument to a function arbitrates, then return True or False, and finally returns True elements into a new list

 

28, a list of all the odd list of requirements to derive the formula and a new list structure, a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

 

29, regular re.complie role

compile a regular expression compiler generates a regular expression (the Pattern) object with a match () and search () these two methods. Speed, and reuse

 

30, a = (1,) b = (1), c = ( "1") are what type of data?

 

31, two lists [1,5,7,9] and [2,2,6,8] merger [1,2,2,3,6,7,8,9]?

may be added individually extend another set to the list of elements, different from the added whole append

 

32, delete files, and delete files in python linux command method

python: os.remove (filename)

linux: rm filename

 

33、log日志中,我们需要用时间戳记录error,warning等的发生时间,请用datetime模块打印当前时间戳 “2018-04-01 11:38:54

顺便把星期的代码也贴上了

 

34、数据库优化查询的方法

外键、索引、联合查询、选择特定字段等等

 

35、请列出你会的任意一种统计图(条形图、折线图等)绘制的开源库,第三方也行

matplotlib

 

36、写一段自定义异常代码

自定义异常用raise抛出异常

 

37、正则表达式匹配中,(.*)和(.*?)匹配区别?

(.*)是贪婪匹配,会把满足正则的尽可能多的往后匹配

(.*?)是非贪婪匹配,会把满足正则的尽可能少匹配

 

38、简述Django的orm

ORM,全拼Object-Relation Mapping,意为对象-关系映射

实现了数据模型与数据库的解耦,通过简单的配置就可以轻松更换数据库,而不需要修改代码只需要面向对象编程,orm操作本质上会根据对接的数据库引擎,翻译成对应的sql语句,所有使用Django开发的项目无需关心程序底层使用的是MySQL、Oracle、sqlite....,如果数据库迁移,只需要更换Django的数据库引擎即可。

 

39、[[1,2],[3,4],[5,6]]一行代码展开该列表,得出[1,2,3,4,5,6]

列表推导式:

x = [[1,2],[3,4],[5,6]]

a = [j for i in a for j in i]

print(a)

或者将列表转成numpy矩阵,通过numpy的flatten()方法:

 

40、x="abc",y="def",z=["d","e","f"],分别求出x.join(y)和x.join(z)返回的结果

join()括号里面的是可迭代对象,x插入可迭代对象中间,形成字符串,结果一致

 

41、举例说明异常模块中try except else finally的相关意义

try..except..else没有捕获到异常,执行else语句

try..except..finally不管是否捕获到异常,都执行finally语句

 

42、python中交换两个数值

 

43、举例说明zip()函数用法

zip()函数在运算时,会以一个或多个序列(可迭代对象)做为参数,返回一个由这些序列中并排的元素配对的元组组成的列表。

zip()参数可以接受任何类型的序列,同时也可以有两个以上的参数;当传入参数的长度不同时,zip能自动以最短序列长度为准进行截取,获得元组。

 

44、a="张明 98分",用re.sub,将98替换为100

Guess you like

Origin blog.csdn.net/qq_42415326/article/details/92705029