我需要在最后一个位置打印而不带逗号 [英] I need to print without comma in last position

查看:34
本文介绍了我需要在最后一个位置打印而不带逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

n = int(input("Enter a number :-"))
for i in range(1, 11):
    print(i*n, end = ",")

当我尝试该程序时,在输出的最后一个位置有一个逗号.但我不要这个逗号.如何删除逗号?我只是将其编码为乘法表.

When I tried this program, in output I have got a comma in the last position. But I don't want this comma. How can I remove the comma? I just code it for a multiplication table.

输出:8,16,24,32,40,48,56,64,72,80,

Output: 8,16,24,32,40,48,56,64,72,80,

推荐答案

您可以在打印前检查索引

You can check the index before printing

n = int(input("Enter a number :-"))
for i in range(1, 11):
    end = "," if i < 10 else ""
    print(i*n, end = end)

这篇关于我需要在最后一个位置打印而不带逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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