gpt4 book ai didi

python - 我们能否像在 Perl 中一样在 Python 中获得以下灵活性

转载 作者:太空狗 更新时间:2023-10-30 02:06:37 24 4
gpt4 key购买 nike

对不起。我不是想挑起任何火焰。我的脚本编写经验来自 Perl,我是 Python 的新手。

我只是想检查我是否可以拥有与 Python 相同程度的灵 active 。

在 Python 中:

page = form.getvalue("page")
str = 'This is string : ' + str(int(page) + 1)

在 Perl 中:

$str = 'This is string : ' . ($page + 1);

有什么办法可以避免 int/str 转换?

最佳答案

不,因为 Python 是强类型的。如果将 page 保留为 int,则可以执行以下操作:

s = 'This is string : %d' % (page + 1,)

关于python - 我们能否像在 Perl 中一样在 Python 中获得以下灵活性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2249419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com