python3基础之“小练习(3)”

(二十四)将字符串"A screaming comes across the sky."中所有的"s"字符替换为美元符号。
1 # a="A screaming comes across the sky."
2 # a=a.replace("s","$")
3 # print(a)
(二十五)找到字符串"Hemingway"中字符"m"所在的第一个索引。
1 # a="Hemingway"
2 # print(a.index("m"))
(二十六)在你最喜欢的书中找一段对话,将其变成一个字符串。
1 # a="岁月不待人"
2 # print(a)
(二十七)先后使用字符串拼接和字符串乘法,创建字符串"three three three"。
1 # a="thr"
2 # b="ee"
3 # c=a+b
4 # print(c)
5 # v=c*3
6 # print(v)
(二十八)对字符串"It was bright cold day in April, and the clocks were striking thirteen."进行切片,只保留逗号之前的字符。
1 # a="It was bright cold day in April,and the clorcks were strking thirteen."
2 # a=a.split(",")
3 # # print(a)
4 # print(a[0:1])
(二十九)打印以下列表["The Walking Dead", "Entourage", "The Sopranos","The Vampire Diaries"]中的每个元素。
1 # q=["The Walking Dead", "Entourage", "The Sopranos","The Vampire Diaries"]
2 # for i in q:
3 #     print(i)
(三十)打印从25 到50 之间的所有数字。
1 # for i in range(25,50):
2 #     print(i)
(三十一)打印第一个挑战练习中的每个元素及其索引。
1 # a=["The Walking Dead", "Entourage", "The Sopranos","The Vampire Diaries"]
2 # for i in a :
3 #     print(i)
4 #     s=a.index(i)
5 #     print(s)
(三十二)编写一个包含死循环和数字列表的程序(可选择输入q 退出)。每次循环时,请用户猜一个在列表中的数字,然后告知其猜测是否正确。
1 # a=input("type a str:")
2 # while a=="b":
3 #     if a=="q":
4 #         break
5 #         end
6 #     print("right!")
(三十三)将列表[8, 19, 148, 4]中的所有数字,与列表[9, 1, 33, 83]中的所有数字相乘,并将结果添加到第3 个列表中。
1 # a=[8,19,148,4]
2 # s=[9,1,33,83]
3 # d=[]
4 # for i in a:
5 #     for j in s:
6 #         d.append(i*j)
7 # print(d)

 

如有不足,欢迎指正!

转载于:https://www.cnblogs.com/wangwenchao/p/11329656.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值