Python容器 之 练习题

1.字符串的基本使用

# 定义一个字符串 str1, 字符串的内容为 "hello world and itcast and itheima and Python"
str1 = "hello world and itcast and itheima and Python"
# 在字符串str1中查找 字符串 and 的下标
num = str1.find('and')
print(num)  # 12
# 在字符串str1中查找字符串 'good'的下标
num1 = str1.find('good')
print(num1)  # -1
# 将字符串str1中的 and 替换为 or
str2 = str1.replace("and", "or")
print(str2)  # hello world or itcast or itheima or Python
# 将字符串 str1 按照 空白字符进行切割,保存到变量 list1 中
list1 = str1.split()
print(list1)  # ['hello', 'world', 'and', 'itcast', 'and', 'itheima', 'and', 'Python']
# 使用 _*_ 将 list1中的字符串进行连接
str3 = "_*_".join(list1)
print(str3)  # hello_*_world_*_and_*_itcast_*_and_*_itheima_*_and_*_Python
# 使用 逗号 将 list1中的字符串进行连接
str4 = ",".join(list1)
print(str4)  # hello,world,and,itcast,and,itheima,and,Python


2.列表的基本使用

# 2.练习对列表的增删改查统计的操作,具体操作如下:
# 1)声明一个列表,包含的数据有:["hello", "python", "itcast", "hello&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

埜玊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值