首页 > 编程语言 > 详细

python--切片

时间:2017-07-09 17:54:18      阅读:200      评论:0      收藏:0      [点我收藏+]

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 

python--切片

原文:http://www.cnblogs.com/zqq521/p/7142059.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!