通过使用加运算符可以进行序列的连接操作
>>> [1,2,3]+[4,5,6]
[1, 2, 3, 4, 5, 6]
两种相同的类型的序列才能进行连接操作
乘法
用数字x乘以一个序列会生成新的序列,而在新的序列中,原来的序列将会被重复x次。
>>> 'you are handsome'*5
'you are handsomeyou are handsomeyou are handsomeyou are handsomeyou are handsome'
None、空列表和初始化
None 代表空的
>>> abc=[None]*10
>>> abc
[None, None, None, None, None, None, None, None, None, None]
乘法示例
#以正确的宽度在居中的“盒子”内打印一个句子
sentence=input("Sentence:")
screen_width=80
text_width=len(sentence)
box_width=text_width+6
left_margin=(screen_width-box_width)//2
print
print (' '*left_margin+'+'+'-'*(box_width-2)+ '+')
print (' '*left_margin+'| '+' '*text_width + ' |')
print (' '*left_margin+'|'+sentence +'|')
print (' '*left_margin+'| '+' '*text_width + ' |')
print (' '*left_margin+'+' +'-'*(box_width-2)+'+')
print
运行结果
Sentence:你好
+------+
| |
|你好|
| |
+------+
>>>