Python打印语句间距

huangapple go评论66阅读模式
英文:

Python Print Statement Spacing

问题

Python Code

phone_number = int(input())

last_four = phone_number % 10000

area_code = phone_number // 10000000

middle_three = (phone_number % 10000000) // 10000

print('(', area_code, ')', middle_three, '-', last_four)

代码中不需要更改,将输出 (800) 格式。

英文:

My Question
How do I remove the spaces in between 800 and the parenthesis surrounding the 800?

For example;

Instead of outputting ( 800 )

I would like it to be (800)

My code is below..

Python Code

phone_number = int(input())

last_four = phone_number % 10000

area_code = phone_number // 10000000

middle_three = (phone_number % 10000000) // 10000

print('(', area_code, ')', middle_three, '-', last_four)

答案1

得分: 2

print(f'({area_code}){middle_three}-{last_four}')

英文:

You can simply use f-strings which are quite powerful and will help you later on as well

print(f'({area_code}){middle_three}-{last_four}')

huangapple
  • 本文由 发表于 2023年3月9日 18:45:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683530.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定