ITPUB??ì3
ITPUB论坛 » 动态语言 » python数据结构练习

新一届的微软MVP评选已经开始,欢迎各位推荐!

标题: [笔记] python数据结构练习
离线 hotiice
版主


精华贴数 10
个人空间 0
技术积分 16699 (62)
社区积分 1796 (648)
注册日期 2004-9-9
论坛徽章:21
现任管理团队成员会员2007贡献徽章铁扇公主生肖徽章2007版:牛2008北京奥运纪念徽章:帆船2008北京奥运纪念徽章:游泳
设计板块每日发贴之星设计板块每日发贴之星生肖徽章2007版:蛇2008年新春纪念徽章生肖徽章2007版:龙生肖徽章2007版:兔

发表于 2006-8-2 16:21 
python数据结构练习

Microsoft Windows [版本 5.2.3790]
(C) 版权所有 1985-2003 Microsoft Corp.

C:\Documents and Settings\lt>cd \py*

C:\Python25>python
Python 2.5b2 (r25b2:50512, Jul 11 2006, 10:16:14) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> stack =[3,4,5]
>>> stack.append(6)
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> stack
[3, 4, 5]
>>> queue =stack
>>> queue.pop(0)
3
>>> queue
[4, 5]
>>> def cu(x):return x*x*x
...
>>> map(cu,queue)
[64, 125]
>>> reduce(cu,queue)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cu() takes exactly 1 argument (2 given)
>>> def ad(x,y):return x+y
...
>>> reduce(ad,queue)
9
>>> del queue(1)
  File "<stdin>", line 1
SyntaxError: can't delete function call
>>> del queue[1]
>>> queue
[4]
>>>


__________________
①②⑧

只看该作者    顶部
离线 hotiice
版主


精华贴数 10
个人空间 0
技术积分 16699 (62)
社区积分 1796 (648)
注册日期 2004-9-9
论坛徽章:21
现任管理团队成员会员2007贡献徽章铁扇公主生肖徽章2007版:牛2008北京奥运纪念徽章:帆船2008北京奥运纪念徽章:游泳
设计板块每日发贴之星设计板块每日发贴之星生肖徽章2007版:蛇2008年新春纪念徽章生肖徽章2007版:龙生肖徽章2007版:兔

发表于 2006-8-2 16:45 
>>> t=1,2,'h'
>>> t
(1, 2, 'h')
>>> u=t,(3,4)
>>> u
((1, 2, 'h'), (3, 4))
>>> x,y,z=t
>>> x
1
>>> y
2
>>> z
'h'
>>> m,n =u
>>> m
(1, 2, 'h')
>>> n
(3, 4)
>>>


__________________
①②⑧

只看该作者    顶部
离线 hotiice
版主


精华贴数 10
个人空间 0
技术积分 16699 (62)
社区积分 1796 (648)
注册日期 2004-9-9
论坛徽章:21
现任管理团队成员会员2007贡献徽章铁扇公主生肖徽章2007版:牛2008北京奥运纪念徽章:帆船2008北京奥运纪念徽章:游泳
设计板块每日发贴之星设计板块每日发贴之星生肖徽章2007版:蛇2008年新春纪念徽章生肖徽章2007版:龙生肖徽章2007版:兔

发表于 2006-8-2 16:48 
>>> a=set('asfghhjjda')
>>> b=set('dkjserxe')
>>> a
set(['a', 'd', 'g', 'f', 'h', 'j', 's'])
>>> b
set(['e', 'd', 'k', 'j', 's', 'r', 'x'])
>>> a+b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'set' and 'set'
>>> a & b
set(['s', 'j', 'd'])
>>> a | b
set(['a', 'e', 'd', 'g', 'f', 'h', 'k', 'j', 's', 'r', 'x'])
>>> a - b
set(['a', 'h', 'g', 'f'])
>>> b - a
set(['x', 'k', 'r', 'e'])
>>> a ^ b
set(['a', 'e', 'g', 'f', 'h', 'k', 'r', 'x'])
>>> b ^ a
set(['a', 'e', 'g', 'f', 'h', 'k', 'r', 'x'])
>>>


__________________
①②⑧

只看该作者    顶部
离线 hotiice
版主


精华贴数 10
个人空间 0
技术积分 16699 (62)
社区积分 1796 (648)
注册日期 2004-9-9
论坛徽章:21
现任管理团队成员会员2007贡献徽章铁扇公主生肖徽章2007版:牛2008北京奥运纪念徽章:帆船2008北京奥运纪念徽章:游泳
设计板块每日发贴之星设计板块每日发贴之星生肖徽章2007版:蛇2008年新春纪念徽章生肖徽章2007版:龙生肖徽章2007版:兔

发表于 2006-8-2 17:39 
>>> import math
>>> dir(math)
['__doc__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod',
'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']
>>> import __builtin__
>>> dir (__builtin__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'Environm
entError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarnin
g', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotIm
plemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'R
untimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True
', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UserW
arning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', 'a
bs', 'all', 'any', 'apply', 'basestring', 'bool', 'buffer', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'compl
ex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'flo
at', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubcl
ass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', 'property'
, 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmet
hod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>>


__________________
①②⑧

只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问