当前位置: 移动技术网 > IT编程>脚本编程>Python > python3基础之“小练习(2)”

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

2019年08月08日  | 移动技术网IT编程  | 我要评论

apple store hk,强奸女主播,普通话学习网

(十三)创建一个你最喜欢歌手的列表。
1 # singer=list()
2 # singer=['a','b','c']
3 # print(singer)


(十四)创建一个由元组构成的列表,每个元组包含居住过或旅游过的城市的经纬度。
1 # s=tuple('1.1','2.2','3.3')
2 # print(s)

(十五)创建一个包含你的不同属性的字典:身高、最喜欢的颜色和最喜欢的作者等。
1 # zi_dian={"height":"1.9m",
2 #          "color":"blue",
3 #          "author":"鲁迅"}
4 # print(zi_dian)

(十六)编写一个程序,让用户询问你的身高、最喜欢的颜色或最喜欢的作者,并返回上一个挑战中创建的字典。
1 # zi_dian={"height":"1.9m",
2 #          "color":"blue",
3 #          "author":"鲁迅"}
4 # print(zi_dian["height"])
5 # print(zi_dian["color"])
6 # print(zi_dian["author"])
7 # print(zi_dian)

(十七)创建一个字典,将最喜欢的歌手映射至你最喜欢的歌曲。
1 # singer={"123":"456",
2 #         "789":"998"}
3 # print("singer")

(十八)列表、元组和容器只是python 中内置容器的一部分。自行研究python 中的集合.(也是一种容器)在什么情况下可以使用集合?
  
  :思考一下,集合与list,tuple的区别

(十九)打印字符串"camus"中的所有字符。
1 # v="camus"
2 # print(v[0])
3 # print(v[1])
4 # print(v[2])
5 # print(v[3])
6 # print(v[4])

(二十)编写程序,从用户处获取两个字符串,将其插入字符串"yesterday i wrote a[用户输入1]. i sent it to [用户输入2]!"中,并打印新字符串。
1 # c=input("type a str:")
2 # d=input("type a str:")
3 # a="yesterday i wrote a {}. i sent it to {}!".format(c,d)
4 # print(a)

(二十一)想办法将字符串"aldous huxley was born in 1894."的第一个字符大写,从而使语法正确。
1 # a="aldous huxley was born in 1894"
2 # v=a.capitalize()
3 # print(v)

(二十二)对字符串"where now? who now? when now?"调用一个方法,返回如下述的列表["where now?", "who now?", "when now?"]。
1 # a="where now? who now? when now? "
2 # v=a.split("?")
3 # print(v)

(二十三)对列表["the", "fox", "jumped", "over", "the", "fence", "."]进行处理,将其变成一个语法正确的字符串。每个单词间以空格符分隔,但是单词fence 和句号之间不能有空格符。(别忘了,我们之前已经学过将字符串列表连接为单个字符串的方法。)
1 # s=["the", "fox", "jumped", "over", "the", "fence", "."]
2 # v=" ".join(s)
3 # v=v.strip()
4 # print(v)

如有错误,欢迎指正!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网