- 博客(46)
- 收藏
- 关注
原创 Python在列表指定位置添加元素
在列表指定位置添加元素Python也提供了insert()方法,可以在列表任意指定位置插入元素,其基本语法为:source_list.insert(index,obj)其中,source_list:为待修改的列表index:为待插入的位置索引obj:为待插入的元素注意:在Python中,列表起始元素的位置索引为0例如,要向guests列表中Zhang san的后面增加客人Hu qi,则相应的语句为:# 创建并初始化guests列表guests=['Zhang san','Li si','Wan
2020-08-05 18:22:56
41803
1
原创 strip去掉首尾空格和指定字符Python
# coding = utf-8# 创建一个字符串hello_worldhello_world = ' **The world ** is big!* '# 利用strip()方法处理hello_world字符串blank_hello_world = hello_world.strip()char_hello_world = hello_world.strip('TH *')# 打印输出转换后的字符串print(blank_hello_world)print(char_hello_w
2020-08-05 18:21:00
750
原创 Python全小写,全大写,首字母大写
# coding=utf-8# 创建一个字符串say_hellosay_hello = 'Dear my Daughter'# 使用upper()方法对say_hello字符串进行处理upper_say_hello = say_hello.upper()# 使用lower()方法对say_hello字符串进行处理lower_say_hello = say_hello.lower()# 使用title()方法对say_hello字符串进行处理title_say_hello = say_hell
2020-08-05 18:19:52
2885
原创 Python创建一个字符串变量,获取其长度并打印出来
# coding=utf-8# 创建一个字符串变量,获取其长度并打印出来color = 'It is red'length = len(color)print (length)#直接在len函数中引入字符串内容获得其长度,然后打印出来print(len('This is a circle!'))输出结果: 9 17...
2020-08-05 18:19:02
2593
原创 字符串中指定位置插入信息
name=input("请输入一个人的名字:")country=input("请输入一个国家的名字:")print("{}来自于{}".format(name,country))输入:张三 中国 输出:张三来自于中国
2020-08-05 18:18:04
312
原创 Python选择字符位置输出
Python选择字符位置输出>>>name="Python语言程序设计">>>name[0]'P'>>>print(name[0],name[7],name[-1])P 言 计>>>print(name[2:-4])thon语言>>>print(name[:6])Python>>>print(name[6:])语言程序设计>>>print(name[:])P
2020-08-05 18:17:00
1387
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅