The magical character of commas in Python

Source: Internet
Author: User

Nothing to do with Python. To brush the PAT again, the output encountered a problem like this:

Topic 1002 topic requires the output of the sum of each of the numbers of N in a row, there are 1 spaces between the phonetic numerals, but there is no space after the last phonetic number in a row,

However, the print statement in Python is followed by a newline character, with a comma followed by a smart line that turns the newline into a space

Attach 1002 Code:

#!/usr/bin/python
ImportSys
N = int(Sys.ARGV[1])
Count=0
whileN!=0:
Count=Count+N%10
N =N/10
Ans=[ ]
whileCount!=0:
Ans.insert(0,Count%10)
Count=Count/10
Dic= {0:"Ling", 1:"Yi", 2:"ER",3:"San",4:"Si",5:"WU",6:"Liu",7:"Qi",8:"BA",9:"JIU"}
forIIn range(Len(Ans)):
PrintDic[Ans[I]],

A comma is primarily a tuple conversion in a type conversion, and a comma is required to convert to a tuple type only when there is only one element in the tuple:

such as: b= (one,) #b为一个元组, and the element has only a single

The magical character of commas in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.