python 序列相加,乘法

通过使用加运算符可以进行序列的连接操作

>>> [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:你好
                                    +------+
                                    |    |
                                    |你好|
                                    |    |
                                    +------+
>>> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值