python face questions one week summary: Thursday

67, lists and briefly describes several methods use magic

__init__: object initialization method

__new__: method of execution when creating an object, single mode will be used

__str__: When using print output object, as long as they are defined __str __ (self) method, it will return in the print data from this method

__del__: Delete method on the object

 

68, the terminal performs python 1.py 22 33 command line to start the program and parameter passing, 1.py the print (sys.argv) what will be the output data?

 

69, set [i for i in range (3)] into the generator

1, a list of expressions [] to () to become a generator

2, candidate function generator occurs yield becomes

 

70, A = "hehheh", trailing spaces removed

 

71, for example to sort the list sorted and ordered, list = [0, -1,3, -10,5,9]

sorted ()  function sort operation on all objects iterations.

sort and sorted differences:

The method is applied on the sort of the list, sorted can be sorted objects operate all iterations.

list sort method returns a list of the existing operation, the built-in function sorted method returns a new list, rather than operation performed on the basis of the original.

grammar

sorted syntax:

sorted(iterable, key=None, reverse=False)  

Parameter Description:

  • iterable - iterables.
  • key - is mainly used for the comparison element, only one parameter, the specific parameter is a function of iteration may be taken from the object, specify one of the elements in the iteration to be sorted.
  • reverse - collation, reverse = True descending, reverse = False ascending (default).

 

72、对foo = [-5,8,0,4,9,-4,-20,-2,8,2,-4],使用lambda函数从小到大排序

 

 

73、使用lambda函数对foo = [-5,8,0,4,9,-4,-20,-2,8,2,-4]排序,输出结果为[0,2,4,8,8,9,-2,-4,-4,-5,-20],正数从小到大,负数从大到小

 

74、列表嵌套字典的排序,分别根据年龄和姓名排序

foo = [{"name":"zs","age":19},{"name":"ll","age":54},

        {"name":"wa","age":17},{"name":"df","age":23}]

 

75、列表嵌套元组,分别按字母和数字排序

 

76、列表嵌套列表排序,年龄数字相同怎么办?

 

77、根据键对字典排序(方法一,zip函数)

 

78、根据键对字典排序(方法二,不用zip)

dic.items和zip(dic.keys(),dic.values())都是为了构造列表嵌套字典的结构,方便后面用sorted()构造排序规则

 

79、列表推导式、字典推导式、生成器

 

80、最后出一道检验题目,根据字符串长度排序,看排序是否灵活运用

 

81、举例说明SQL注入和解决办法

当以字符串格式化书写方式的时候,如果用户输入的有;+SQL语句,后面的SQL语句会执行,比如例子中的SQL注入会删除数据库demo

解决方式:通过传参数方式解决SQL注入

 

82、s="info:xiaoZhang 33 shandong",用正则切分字符串输出['info', 'xiaoZhang', '33', 'shandong']

|表示或,根据冒号或者空格切分

 

83、正则匹配以163.com结尾的邮箱

 

84、递归求和

 

85、python字典和json字符串相互转化方法​​​​​​​

json.dumps()字典转json字符串,'

json.loads() json转字典

 

86、MyISAM 与 InnoDB 区别:

1、InnoDB 支持事务,MyISAM 不支持,这一点是非常之重要。事务是一种高级的处理方式,如在一些列增删改中只要哪个出错还可以回滚还原,而 MyISAM就不可以了;

2、MyISAM 适合查询以及插入为主的应用,InnoDB 适合频繁修改以及涉及到安全性较高的应用;

3、InnoDB 支持外键,MyISAM 不支持;

4、对于自增长的字段,InnoDB 中必须包含只有该字段的索引,但是在 MyISAM表中可以和其他字段一起建立联合索引;

5、清空整个表时,InnoDB 是一行一行的删除,效率非常慢。MyISAM 则会重建表;

 

87、统计字符串中某字符出现次数

 

88、字符串转化大小写

Guess you like

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