且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将列表的单个元素与数字相乘?

更新时间:2023-02-10 15:38:27

您可以使用内置的 map 函数:

You can use built-in map function:

result = map(lambda x: x * P, S)

列表推导 更像 Python:>

or list comprehensions that is a bit more pythonic:

result = [x * P for x in S]