在 Python 中声明一个数字.可以强调千吗? [英] Declaring a number in Python. Possible to emphasize thousand?

查看:35
本文介绍了在 Python 中声明一个数字.可以强调千吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Python 中将数字声明为

Is it possible to declare a number in Python as

a = 35_000
a = 35,000  

当然似乎都不起作用.为了在 Python 中清晰起见,您如何强调这些内容?可能吗?

Neither seem to work of course. How do you emphasize things like these, for clarity in Python? Is it possible?

推荐答案

这实际上是 现在可能在 Python 3.6 中.

This is actually just now possible in Python 3.6.

您可以使用您显示的第一种格式:

You can use the first format that you showed:

a = 35_000

因为下划线现在是可接受的数字分隔符.(你甚至可以说a = 3_5_00_0,但你为什么要说?)

because underscores are now an accepted separator in numbers. (You could even say a = 3_5_00_0, though why would you?)

您展示的第二种方法实际上会创建一个元组.就像在说:

The second method you showed will actually create a tuple. It's the same as saying:

a = (35, 000)  # Which is also the same as (35, 0).

这篇关于在 Python 中声明一个数字.可以强调千吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆