python逗号分隔符_在Python中用逗号将数字打印为数千个分隔符

python逗号分隔符

什么是质数? (What is a prime number?)

Many times, while writing the code we need to print the large number separated i.e. thousands separators with commas.

很多时候,在编写代码时,我们需要打印大量的分隔符,即用逗号分隔数千个分隔符。

In python, such formatting is easy. Consider the below syntax to format a number with commas (thousands separators).

在python中,这种格式很容易。 考虑以下语法,以逗号分隔数字(千位分隔符)

    "{:,}".format(n)
    Here, n is the number to be formatted.

Given a number n, we have to print it with commas as thousands separators.

给定数字n ,我们必须用逗号将其打印为数千个分隔符。

Example:

例:

    Input:
    n = 1234567890
    
    Output:
    1,234,567,890

Python程序以逗号分隔的形式将数字打印为Python中的数千个分隔符 (Python program to print number with commas as thousands separators in Python)

# function to return number with thousand separator
def formattedNumber(n):
  return ("{:,}".format(n)) 

# Main code
print(formattedNumber(10))
print(formattedNumber(100))
print(formattedNumber(1000))
print(formattedNumber(10000))
print(formattedNumber(100000))
print(formattedNumber(1234567890))
print(formattedNumber(892887872878))

Output

输出量

10
100
1,000
10,000
100,000
1,234,567,890
892,887,872,878


翻译自: https://www.includehelp.com/python/print-number-with-commas-as-thousands-separators.aspx

python逗号分隔符

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值