码迷,mamicode.com
首页 > 编程语言 > 详细

Python(3)

时间:2016-09-10 19:03:45      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

>>> 5 ** 2  # 5 squared
25
>>> 2 ** 7  # 2 to the power of 7
128
>>> 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)

标签:

原文地址:http://www.cnblogs.com/gottheg/p/5859838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!