word="abcdefg"
a=word[2]
print "a is: "+a
b=word[1:3]
print "b is: "+b # index 1 and 2 elements of word.
c=word[:2]
print "c is: "+c # index 0 and 1 elements of word.
d=word[0:]
print "d is: "+d # All elements of word.
e=word[:2]+word[2:]
print "e is: "+e # All elements of word.
f=word[-1]
print "f is: "+f # The last elements of word.
g=word[-4:-2]
print "g is: "+g # index 3 and 4 elements of word.
h=word[-2:]
print "h is: "+h # The last two elements.
i=word[:-2]
print "i is: "+i # Everything except the last two characters
l=len(word)
print "Length of word is: "+ str(l)
a is: c
b is: bc
c is: ab
d is: abcdefg
e is: abcdefg
f is: g
g is: de
h is: fg
i is: abcde
Length of word is: 7
相关推荐
jmu-python-字符串异常处理.txt
python 字符串反转方法 Python是一种高级编程语言,它提供了许多内置函数和方法,其中包括字符串反转方法。在本文中,我们将探讨如何使用Python中的字符串反转方法来反转字符串。 Python中的字符串是一系列字符的...
title: Python 字符串的replace函数字符串的replace函数功能将字符串中的old(旧元素)替换成new(新元素),并能指定替换的数量用法n
title: Python 字符串的strip函数字符串的strip函数功能string将去掉字符串左右两边的指定元素,默认是空格用法参数括弧里需要传一个你想去
title: Python 字符串的startswith和endswith函数字符串的startswith和endswith函数功能startswith判断字符
功能:判断字符串是否是一个标题类型用法注意:该函数只能用于英文isupper与islower功能:isupper判断字符串中的字母是否都是大写islower判断
python学习笔记,包括python入门-数据类型-数字变量-字符串-索引和分片
1.去除字符串头尾空格 2.判断符号 3.提取出数字字符直到第一个不为数字的字符 4.字符串转整数,乘以符号 4.判断是否超出整数范围,并返回相应的值
《Python编程基础与应用》电子教案 Python编程基础与应用-教案0301-字符串的应用(一)[3页]全文共3页,当前为第1页。 Python编程基础与应用-教案0301-字符串的应用(一)[3页]全文共3页,当前为第1页。 课题 字符串的...
python实现字符串模糊匹配
第二周-第11章节-Python3.5-字符串常用操作.avi
Python教程-字符串详解及序列类型.pdf
初学者,软件测试工程师
所以有些Python程序员会说Python没有变量,只有名字。变量就是一个名字,通过这个名字,我们能找到我们想要的东西。\nteacher='\u5c0f\u4e4c\u9f9f' print(teacher) 结果: 小乌龟 变量为什么不叫“恒量”而是叫变量...
解析字符串使用基于Python format() 语法的规范
本文实例为大家分享了python实现字符串加密成纯数字的具体代码,供大家参考,具体内容如下 说明: 该加密算法仅仅是做一个简单的加密,安全性就不谈了,哈哈. 算法流程:
——学习参考资料:仅用于个人学习使用! 本代码仅作学习交流,切勿用于商业用途,否则后果自负。若涉及侵权,请联系,会尽快处理! 未进行详尽测试,请自行调试!
python 实现 整数翻转-字符串
python地下水位预测-09-字符串常用操作方法之修改之字符串对齐.ev4.rar
下表实例变量a值为字符串 "Hello",b变量值为 "Python": 操作符 描述 实例 + 字符串连接 a + b 输出结果: HelloPython * 重复输出字符串 a*2 输出结果:HelloHello [] 通过索引获取字符串中字符 a[1] 输出结果 e ...