Python 打印返回 null

问题描述 投票:0回答:1

当我执行此代码时,它返回 None,但我想像循环中那样打印整数,有人知道为什么吗?

import boto3
client = boto3.client('autoscaling')
clearesponse = client.describe_auto_scaling_groups(
    AutoScalingGroupNames=[
        'XXXX',
    ])


for reservation in clearesponse ['AutoScalingGroups']:
        test=print(reservation['DesiredCapacity'])


nb_desired_cap = test
print (nb_desired_cap)
print (test)

运行:

python 描述实例.py

4

运行代码并希望在其他变量中捕获结果 4 以用于代码的其他部分

python amazon-web-services loops variables boto3
1个回答
1
投票

这是因为

print
函数返回
None

>>> result = print("Hello, World!")
Hello, World!
>>> result is None
True

我不确定您希望代码执行什么操作,但您可能希望为变量分配除

print
返回的结果之外的其他内容。

© www.soinside.com 2019 - 2024. All rights reserved.