首页 > 代码库 > Python(3)

Python(3)

>>> 5 ** 2  # 5 squared25>>> 2 ** 7  # 2 to the power of 7128
>>> 3 * ‘un‘ + ‘ium‘‘unununium‘
>>> text = (‘Put several strings within parentheses ‘...         ‘to have them joined together.‘)>>> text‘Put several strings within parentheses to have them joined together.‘

>>> word = ‘Python‘
>>> word[-1]  # last character‘n‘>>> word[-2]  # second-last character‘o‘>>> word[-6]‘P‘
>>> word[0] = ‘J‘  ...TypeError: ‘str‘ object does not support item assignment>>> word[2:] = ‘py‘  ...TypeError: ‘str‘ object does not support item assignment
>>> squares + [36, 49, 64, 81, 100][1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
>>> letters = [‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘]>>> letters[‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘]>>> # replace some values>>> letters[2:5] = [‘C‘, ‘D‘, ‘E‘]>>> letters[‘a‘, ‘b‘, ‘C‘, ‘D‘, ‘E‘, ‘f‘, ‘g‘]>>> # now remove them>>> letters[2:5] = []>>> letters[‘a‘, ‘b‘, ‘f‘, ‘g‘]>>> # clear the list by replacing all the elements with an empty list>>> letters[:] = []>>> letters[]
>>> a = [‘a‘, ‘b‘, ‘c‘]>>> n = [1, 2, 3]>>> x = [a, n]>>> x[[‘a‘, ‘b‘, ‘c‘], [1, 2, 3]]>>> x[0][‘a‘, ‘b‘, ‘c‘]>>> x[0][1]‘b‘
 

Python(3)