码迷,mamicode.com
首页 > 其他好文 > 详细

字符串的索引和切片

时间:2016-08-02 00:45:49      阅读:658      评论:0      收藏:0      [点我收藏+]

标签:

本文主要介绍:字符串的索引,切片及求字符串的长度

代码:

 

#!/usr/bin/env python
# author by lh
# -*- coding:utf-8 -*-
s=‘hello‘
ret=len(s)
print ret
ret1=s[0:3]
print ret1
print s[0]
print s[1]
print s[2]
print s[3]
print s[4]

 

运行结果:

技术分享

 

字符串的索引和切片

标签:

原文地址:http://www.cnblogs.com/pythonlh/p/5727512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!