从0.2开始学Python,第5天——处理练习、元组
本帖最后由 WoShiXXX 于 2021-11-3 17:32 编辑由于楼主最近时间有点紧,所以今天不更新太多新内容,处理之前的练习。楼主为八年级学生,想要冲冲编程竞赛,但无奈自己智商不够,没法撸各种算法题,只好先从比较简单的Python开始,开一些帖子记录一下。由于我有前端基础,所以我并不是0基础,而是0.2基础{:301_997:}。我随时可能拖更,如果我长时间拖更,欢迎催更!我选用的是Python编程:从入门到实践(第2版).pdf这本书当作教材,这本书前30页都是废话。
练习3-1至3-7
names = ["Zhang San", "Li Si", "Wang Wu"]
for name in names:
print(name)
for name in names:
print(f"Hello, my friend {name}")
print("Would you like to come to my home for dinner?")
print(f"But {names},you can't come,so I'll remove you in the list.")
names.remove("Zhang San")
names.append("Zhao Liu")
print(f"I invited {names}")
print("Oh, I found a bigger table.I'll invite more people!")
names.insert(0,"Grandpa")
names.insert(3,"Father")
names.append("Mother")
print(names)
print(f"I invited {len(names)} people.")
练习4-3:
for value in range(1,21):
print(value)
练习4-4、4-5:
numbers = range(1,1_000_001)
print(min(numbers))
print(max(numbers))
print(sum(numbers))
练习4-6至4-10
print(list(range(1,21,2)))
print(list(range(3,31,3)))
nums = list(range(1,11))
newNums = []
for num in nums:
newNums.append(num ** 3)
print(newNums)
Nums2 =
print(Nums2)
print(f"The first three items are:{nums}")
print(f"Three items from the middle of the list are:{nums}")
print(f"The last three items are:{nums}")
元组
元组与列表类似,不过其中的值不能修改,用圆括号而不是方括号括起来表示。dimensions = (200, 50)
for dimension in dimensions:
print(dimension)
但当只有一个元素时,需要用逗号分隔,否则会产生歧义。
my_t = (3,)
我们不能修改元组的值,但可以给元组变量一个新的元组(这也印证了之前说过的:只是一个指针,而不是一个存储值的盒子)
dimensions = (200, 50)
print("Original dimensions:")
for dimension in dimensions:
print(dimension)
dimensions = (400, 100)
print("\nModified dimensions:")
for dimension in dimensions:
print(dimension)
练习4-13我的答案:
foods = ("Hamburger", "Pizza", "Chips", "Fried chicken", "Tomato soup")
for food in foods:
print(food)
foods = ("Hamburger", "Pizza", "Gongbao chicken", "Fried chicken", "Roasted duck")
for food in foods:
print(food)
其实0.2比0更难学,总觉得比纯新手会的多一点,很自然的就不谦虚了。
另外,楼主学习的这本书,有个萌妹子在B站录了教学视频,学起来精神抖擞,事半功倍,不妨一试。(强烈推荐,谁用谁说好!!!)
传送门:https://www.bilibili.com/video/BV19t411m7uU?from=search&seid=9552110427343570700 个人建议这种基础的 可以稍微理解就行后面你会一直用到 写多了就懂了 加油,望早日产出有趣的小脚本 加油,其实列表和元组可以做为一节,字典再做一节! 有没有写某个网站的自动签到教程 你咋那么优秀呢?我八年级的时候屁也不会!{:1_936:} Python从入门到实践(第二版)分享过期了,能在分享一下嘛~ houhongye 发表于 2021-11-3 19:09
Python从入门到实践(第二版)分享过期了,能在分享一下嘛~
pan.sgguo.com/s/epHE 八年级就是初三吗?后生可畏!
页:
[1]
2