如何让我的代码在每个输出上显示带有字符串的值?

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

你好,我是Python新手,我正在寻找一些额外的帮助。

代码片段:

def cube(side):
  volume =  side **3
  surface_area = 6 * (side**2)
  return volume, surface_area
my_cube = cube(5) 
print(my_cube)

#输出为125,150

在上面的代码中,我希望输出包含如下语句:

“体积为125,表面积为150”

python string function
1个回答
0
投票

使用f弦

print(f"The volume is {volume}, and The surface area is {surface_area}")
© www.soinside.com 2019 - 2024. All rights reserved.