【问题标题】:I know that map returns an iterator, but how can we assign an iterator to a and b?我知道 map 返回一个迭代器,但是我们如何将迭代器分配给 a 和 b?
【发布时间】:2020-11-26 11:12:26
【问题描述】:

下面的代码是做什么的?

a, b = map(int, input().split())

我知道 map 返回一个迭代器,但是我们如何为 a 和 b 分配一个迭代器呢?这像元组赋值吗?

为了理解它,我做了以下操作:

a, b = iter(range(1, 3))
print(a + b)

我知道会发生什么,但我无法完全理解它是如何工作的。谁能解释一下?

【问题讨论】:

标签: python iterator


【解决方案1】:

映射用于与所有值交互并更改它的值而无需编写函数它被称为匿名函数在这里你取a,b等于输入,在python中,你可以定义并取两个值Python。 split 用于拆分特定值。

 a = 'apple is good'
 print(a.split()) # ['apple','is','good']

【讨论】:

    猜你喜欢
    • 2015-06-27
    • 1970-01-01
    • 2021-02-11
    • 2010-09-23
    • 2011-05-17
    • 2020-09-30
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多