1. 获取两个list 的交集#方法一:a=[2,3,4,5]b=[2,5,8]tmp = [val for val in a if val in b] #列表推导式求的两个列表的交集print tmp#[2, 5]#方法二print list(set(a).intersection(set(b))) #列用集合的取交集方法2. 获取两个list 的并集print list(s...【阅读全文】
[root@localhost ~]# python test.py请输入qwerTraceback (most recent call last): File "test.py", line 3, in <module> a = input('请输入') File "<string>", line 1, in <module>NameError: name 'qwer' is not definedtest.py文件内容如下[root@localhost ~]# cat test.py...【阅读全文】
[root@server testpython]# python server.py File "server.py", line 8SyntaxError: Non-ASCII character '\xe7' in file server.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details报错原因:因为Python在默认状态下不支持源文件中的编码所致解决办法:#!/us...【阅读全文】
单线程:from time import ctime,sleepdef music(): for i in range(2): print "I was listening to music. %s" %ctime() sleep(1)def move(): for i in range(2): print "I was at the movies! %s...【阅读全文】
centos7中编辑python脚本时,导入了psutil模块,在执行时出错[root@server ~]# ./hello.pyTraceback (most recent call last): File "./hello.py", line 2, in import psutilModuleNotFoundError: No module named 'psutil'【阅读全文】