首页 > 代码库 > 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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。