python_code list_1

>>> def is_not_empty(s):
return s and len(s.strip()) > 0

>>> filter(is_not_empty, ['test', None, '', 'str', ' ', 'END'])
<filter object at 0x1056a3518>
>>> chr(0x1056a3518)
Traceback (most recent call last):
File "<pyshell#113>", line 1, in <module>
chr(0x1056a3518)
OverflowError: signed integer is greater than maximum
>>> hex(9)
'0x9'
>>> hex(226)
'0xe2'
>>> help(hex)
Help on built-in function hex in module builtins:

hex(number, /)
Return the hexadecimal representation of an integer.

>>> hex(12648430)
'0xc0ffee'

>>> input('please input keyword,thank you')
please input keyword,thank you02
'02'
>>> list([1,2,3])
[1, 2, 3]
>>> set([1.1,2,3])
{1.1, 2, 3}
>>> tuple([1,'str',5.0])
(1, 'str', 5.0)
>>> dict([2:1.2,5:3.2])
SyntaxError: invalid syntax
>>> dict([2:'name',3:'stress'])

SyntaxError: invalid syntax
>>> dict([2 : 'name',3 : 'stress'])
SyntaxError: invalid syntax
>>> dict(a='a',b='b',t='t')
{'b': 'b', 't': 't', 'a': 'a'}
>>> a = set([(1,2)])
>>> dict(a)
{1: 2}
>>> a = [(1,'a'),['a',1]]
>>> dict(a)
{1: 'a', 'a': 1}
>>> a = ('ac',set('de'))
>>> dict(a)
{'e': 'd', 'a': 'c'}
>>> def f(x)
SyntaxError: invalid syntax
>>> def f(x):
return x*x

>>> print map(f,[1,2,3,4,5,6,7,8,8])
SyntaxError: invalid syntax
>>> max([2,4,6,8,9])
9
>>> min([1,0.5,8,6])
0.5
>>> a = iter('abcd')
>>> next(a)
'a'
>>> next(a)
'b'
>>> next(a)
'c'
>>> next(a)
'd'
>>> next(a,'e')
'e'
>>> sum([1,5,8,9])
23
>>> oct(138)
'0o212'
>>> ord('a')
97
>>> pow(2,3)
8
>>> range(1,3)
range(1, 3)
>>> range(1,5,2)
range(1, 5, 2)
>>> range(5)#not include five
range(0, 5)
>>> reversed
<class 'reversed'>
>>> reversed([1,2,3,4,5,6,7])
<list_reverseiterator object at 0x105686f60>
>>> round(1.5778,2)
1.58
>>> str(5648+)
SyntaxError: invalid syntax
>>> str(546)
'546'
>>> str(545.)
'545.0'
>>> type(str)
<class 'type'>
>>> type(132)
<class 'int'>
>>> x = [1,2,3]
>>> y = [4,5,6]
>>> z = [7,8,9]
>>> xyz = zip(x,y,z)
>>> print xyz
SyntaxError: Missing parentheses in call to 'print'
>>> print (xyz)
<zip object at 0x1056a8f08>
>>> import (sys.builtin_module_names)
SyntaxError: invalid syntax
>>> import sys
>>> print(sys.builtin_module_names)
('_ast', '_codecs', '_collections', '_functools', '_imp', '_io', '_locale', '_operator', '_signal', '_sre', '_stat', '_string', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', 'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'posix', 'pwd', 'sys', 'time', 'xxsubtype', 'zipimport')
>>> help('module')
No Python documentation found for 'module'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

>>> help(_ast)
Traceback (most recent call last):
File "<pyshell#169>", line 1, in <module>
help(_ast)
NameError: name '_ast' is not defined
>>> help('_ast')

原文地址:https://www.cnblogs.com/cmnz/p/6875526.html