python--切片

1.切片:

>>> s="abcdefghi"

>>> s[1:7:2]#隔两个取
'bdf'

>>> s
'abcdefghi'
>>> s[::-1]
'ihgfedcba'
>>> s[-1]
'i'
>>>

 

 

 

2.#用户输入的形式,输出每次输入字符串最后最后一个字母

a=raw_input("please input a string1:")
b=raw_input("please input a string2:")
c=raw_input("please input a string3:")
print a[-1]+b[-1]+c[-1]

输出结果

please input a string1:hello
please input a string2:python
please input a string3:mysql
onl
3.#用户输入三个单词,

#coding=utf-8

def totalstr():
s=""
while 1:
a=raw_input("please input a string:")
if a==".":
break
else:
s+=a[-1]
print s
totalstr()

4.#在txt文档中写中文的时候惯用写法:

 raw_input("请输入一个单词:".decode("utf-8").encode("gbk")
 5.位运算:
 右移1位表示把原有数字大小除2

左移一位表示把数字大小乘2 
6.is

 

转载于:https://www.cnblogs.com/zqq521/p/7142059.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值