pi
pi@raspberrypi ~ $ python Python 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> names = ('xupeng','yanfeng','dylon'); >>> print names[3]; Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: tuple index out of range >>> print names[2]; dylon >>> print names[1:2]; ('yanfeng',) >>> print names[0:2]; ('xupeng', 'yanfeng') >>> print names[-1]; dylon >>> print names[-1]+names[0]; dylonxupeng >>> print xupeng in names Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'xupeng' is not defined >>> print 'xupeng' in names True >>> print names[1]*3 yanfengyanfengyanfeng >>> print names[::] ('xupeng', 'yanfeng', 'dylon') >>> s='12345679' >>> s[::-2] '9642' >>> i=-2 >>> for i in range(-1,-len(s),-1): ... print i; File "<stdin>", line 2 print i; ^ IndentationError: expected an indented block >>> print i; -2 >>> len(s) 8 >>> for i in range(-1,-len(s),-1): ... print s[:i] ... 1234567 123456 12345 1234 123 12 1 >>> for i in range(-1,-len(s),-1): ... print s[:i];print i; ... 1234567 -1 123456 -2 12345 -3 1234 -4 123 -5 12 -6 1 -7 >>> for i in range(-1,-len(s),1): ... print s[:i];print i; ... >>> for i in range(-1,-len(s),1): ... print s[:i];print i; ... >>> >>> >>> >>> for i in range(-1,-len(s),-1): ... print s[:i];print i; ... 1234567 -1 123456 -2 12345 -3 1234 -4 123 -5 12 -6 1 -7 >>> s[:-1] '1234567' >>> s[:2] '12' >>> s[:3] '123' >>> s[:-2] '123456' >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']