>>> dir('s')
>>> help('s'.rfind)
>>> a={1, 2, 3}
>>> b={2, 3, 4}
>>> a & b
set([2, 3])
>>> a | b
set([1, 2, 3, 4])
>>> a - b
set([1])
# Конкантенация
>>> "a" 'b'
'ab'
# Третий предел
>>> s="asdfghjklqwerty"
>>> s[::3]
'afjqr'
# Удалять можно сразу срез
l = [0, 1, 2, 3, 4, 5, 6]
>>> del l[2:]
или
>>> del l[::2]
# Генерация словаря
>>> v = [1, 2, 3]
>>> k = ['a', 'b', 'c']
>>> dict(zip(k,v))
{'a': 1, 'b': 2, 'c': 3}
>>> dict.fromkeys(k)
{'a': None, 'b': None, 'c': None}
>>> dict.fromkeys(k, 0)
{'a': None, 'b': 0, 'c': 0}
>>> dict(a = 1, b = 2)
{'a': 1, 'b': 2}
>>> {'a': 1, 'b': 2, 'c': 3}.items()
[('a', 1), ('c', 3), ('b', 2)]
Aug 16, 2011
Python
Labels:
core python,
python
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment