首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Python数据分析(中英对照)·Tuples 元组

元组是不可变的序列,通常用于存储异构数据。 Tuples are immutable sequences typically used to store heterogeneous data. 查看元组的最佳方式是将其作为一个由多个不同部分组成的单个对象。 The best way to view tuples is as a single object that consists of several different parts. 元组在Python编程中有很多用途。 Tuples have many uses in Python programming. 一个特别重要的用例是当您希望从Python函数返回多个对象时。 One especially important use case is when you want to return more than one object from your Python function. 在这种情况下,您通常会将所有这些对象包装在一个元组对象中,然后返回该元组。 In that case, you would typically wrap all of those objects within a single tuple object, and then return that tuple. 现在让我们看一下使用元组可以执行的一些基本操作。 Let’s now take a look at some of the basic operations that we can do using tuples. 我首先要构造一个元组。 I’m first going to construct a tuple. 我将把它称为大写字母T,让我们在元组中输入一些数字。 I’m going to just call it capital T. And let’s just put in a few numbers in my tuple. 比如说1,3,5,7。 Let’s say 1, 3, 5, and 7. 同样,元组是序列的一种类型。 Again, tuples are a type of sequence. 因此,如果我想知道元组中有多少个对象,我可以使用len函数。 So if I wanted to know how many objects I have in my tuple,I can use the len function. 我还可以连接元组。 I can also concatenate tuples. 所以我可以做一些像T+。 So I can do something like T plus. 我需要一个新的元组。 I need a new tuple here. 比如说9号和11号。 Let’s say 9 and 11. 在本例中,Python向我返回一个新的元组,其中两个元组被放在一起。 And in this case, Python returns a new tuple to me where the two tuples have been put together. 因为元组是序列,所以访问元组中不同对象的方式取决于它们的位置。 Because tuples are sequences, the way you access different objects within a tuple is by their position. 因此,如果我想访问元组中的第二个对象,我会键入大写字母T、方括号和1。 So if I wanted to access the second object in my tuple,I would type capital T, square bracket, and 1. 记住,使用位置1将得到元组中的第二个对象,因为Python中的索引从0开始。 And remember, using position 1 is going to give me the second object in the tuple, because indices in Python start at 0. 您需要熟悉的另一个操作是如何打包和解包元组。 Another operation that you need to be familiar with is how to pack and unpack tuples. 假设我有两个数字,两个变量,x和y。 Imagine I have two numbers– two variables, x and y. 让我们快速创建它们。 Let’s just quickly create them.

02

大数据技术之_16_Scala学习_07_数据结构(上)-集合

1、Set、Map 是 Java 中也有的集合。   2、Seq 是 Java 中没有的,我们发现 List 归属到 Seq 了,因此这里的 List 就和 java 不是同一个概念了。   3、我们前面的 for 循环有一个 1 to 3,就是 IndexedSeq 下的 Vector。   4、String 也是属于 IndexeSeq。   5、我们发现经典的数据结构,比如 Queue 和 Stack 被归属到 LinearSeq。   6、大家注意 Scala 中的 Map 体系有一个 SortedMap,说明 Scala 的 Map 可以支持排序。   7、IndexSeq 和 LinearSeq 的区别     IndexSeq 是通过索引来查找和定位,因此速度快,比如 String 就是一个索引集合,通过索引即可定位。     LineaSeq 是线型的,即有头尾的概念,这种数据结构一般是通过遍历来查找,它的价值在于应用到一些具体的应用场景(比如:电商网站,大数据推荐系统:最近浏览的10个商品)。

01

Python时间模块 time 解读

python中时间日期格式化符号:   %y 两位数的年份表示(00-99)   %Y 四位数的年份表示(000-9999)   %m 月份(01-12)   %d 月内中的一天(0-31)   %H 24小时制小时数(0-23)   %I 12小时制小时数(01-12)    %M 分钟数(00=59)   %S 秒(00-59)   %a 本地简化星期名称   %A 本地完整星期名称   %b 本地简化的月份名称   %B 本地完整的月份名称   %c 本地相应的日期表示和时间表示   %j 年内的一天(001-366)   %p 本地A.M.或P.M.的等价符   %U 一年中的星期数(00-53)星期天为星期的开始   %w 星期(0-6),星期天为星期的开始   %W 一年中的星期数(00-53)星期一为星期的开始   %x 本地相应的日期表示   %X 本地相应的时间表示   %Z 当前时区的名称   %% %号本身

02
领券