本篇文章是一篇关于输出元素的帖子
《Python for Beginners》为LearnStreet上的Python入门课程。本节要主学习内容为Lists and Tuples。
Lesson 6 Lists and Tuples
1. Length of List
盘算List变量的度长。
1 def run(var): 2 #return your code here 3 return len(var) 4 5 #This is just for you to see what happens when the function is called 6 print run([1,2,3,4,5])
输出结果:
5
2. Removing Elements of a List
移除表列中的某个元素。
days = ["funday","sunday","monday","tuesday","wednesday","thursday","friday"]
days.pop(0)
注意:pop(0)应用的是圆括号。
3. Appending Lists
在表列尾末加添元素。
days.append("saturday")
其中,days为List型类变量。
4. Concatenating Lists
连接两个表列。
1 def run(first, second): 2 #your code here 3 return first + second 4 5 #This is just for you to see what happens when the function is called 6 print run([1,2,3],[4,5,6])
输出结果:
[1, 2, 3, 4, 5, 6]
5. Tuples
建创tuple变量应用圆括号而不是方括号,tuple型类的变量值是不可变的。
例如:tup = (10, 20, 30)
每日一道理
美丽是平凡的,平凡得让你感觉不到她的存在;美丽是平淡的,平淡得只剩下温馨的回忆;美丽又是平静的,平静得只有你费尽心思才能激起她的涟漪。
美丽是平凡的,平凡得让你感觉不到她的存在;美丽是平淡的,平淡得只剩下温馨的回忆;美丽又是平静的,平静得只有你费尽心思才能激起她的涟漪。
1 def run(): 2 #your code here 3 name = ("Guinevere", 9102) 4 return name 5 6 #This is just for you to see what happens when the function is called 7 print run()
输出结果:
('Guinevere', 9102)
6. 温习训练
1 # assume lst is a list and tup is a tuple 2 def run(lst, tup): 3 #your code here 4 if lst[1] == tup[1]: 5 return tuple(lst) == tup 6 else: 7 return "not equal" 8 9 #This is just for you to see what happens when the function is called 10 print run([1,2,3],(1,2,3))
输出结果:
True
注意:型类转换tuple(lst)
总结:
tuple和list是两种不同的数据型类,他们远永不会等相。但是他们外部的元素都是string型类,可以行进比拟。
文章结束给大家分享下程序员的一些笑话语录: 真正的程序员喜欢兼卖爆米花,他们利用CPU散发出的热量做爆米花,可以根据米花爆裂的速度听出正在运行什么程序。
相关推荐
Python Programming for Beginners 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
When you purchase Python: Programming Language for Beginners - Learn In A Day, you'll find out the importance of this language, and how to begin improving your skills! These fun and easy tips ...
Introduction to python for Beginners.pptx
Python: Practical Python Programming For Beginners and Experts English | 9 July 2016 | ISBN: 1535192976 | 170 Pages Start work on your website, app, or search engine today with this practical Python ...
Python in 8 Hours, Python for Beginners, Learn Python fast! A Smart way to learn Python, Python programming, Python in easy steps: A Beginner's Guide, Fast & Easy! by Ray Yao English | Feb. 28, 2016 ...
Python Programming for Beginners Easy Steps to Learn the Python Language and Go from Beginner to Expert Today!
**Python编程初学者指南:入门...总之,《Python Programming for Beginners》这本书是Python初学者的绝佳资源,它将带你逐步了解Python的核心概念,并通过实践来巩固这些知识,助你快速成为一名合格的Python程序员。
epub完整版 Python Machine Learning.Practical Guide for Beginners.epub
- **在线资源**:鼓励学习者在空闲时间自学课程笔记,或者参考网络上的Python教程。 - **其他课程链接**:提供了指向“Python: Introduction for Absolute Beginners”课程详情页面的链接。 ### 特别提示 - 课程...
Python: Learn Python in 24 Hours: Complete Beginners Guide English | 19 July 2016 | ASIN: B01IRGB6MY | 110 Pages If you are one of them who easily get scared of Python’s long, complicated code, then...
Packt.Python.Artificial.Intelligence.Projects.for.Beginners.2018
### Packt Python初学者指南:人工智能 #### 一、书籍概览 《Packt Python 初学者指南:人工智能》是一本旨在帮助读者掌握利用Python进行人工智能开发的基础与实践的书籍。该书由多位作者共同编写,包括Denis ...
Apache Spark 2.0 for Beginners English | ISBN: 1785885006 | 2016 | Key Features This book offers an easy introduction to the Spark framework published on the latest version of Apache Spark 2 Perform ...
【Python 3 for Absolute Beginners】是一本专为Python编程初学者设计的教程,它涵盖了从基础到进阶的全面知识,旨在帮助新手快速掌握Python 3这一强大的编程语言。在这个教程中,你将学习到: 1. **安装Python 3**...
### Django for Beginners – 学习Web开发(William S. Vincent) #### 介绍 《Django for Beginners》是一本面向初学者的书籍,旨在通过实践项目的方式教授如何使用Django框架进行Web开发。本书作者William S. ...
3. **控制结构**:Python的流程控制语句包括条件判断(if-else)、循环(for、while)以及异常处理(try-except)。这些语句在编写逻辑时起到关键作用。 4. **函数与模块**:Python中的函数是一段可重复使用的代码...