"Python" questions about the format parameters of Python

Source: Internet
Author: User
Tags string format

The last time I used a string format parameter in Python and encountered an operator priority problem, it took a long time to find the problem and record it here.

Two variables were defined at the time:

Datacenter = Int (sys.argv[1= Int (sys.argv[2])

This means that both datacenter and client are of type int. And then call the following sentence when the error occurs.

Dc_net = Self.addswitch ('s%d' % datacenter+client+1)

Hint can not be str and int splicing, but I thought clearly datacenter and client are int, want to add up why say can't splicing it.

Later analysis should be the priority of the problem, the above sentence by default, the%d parameter is set to datacenter, then this sentence becomes a str+int+1 form, will naturally error.

So it's better to do this:

Dc_net = Self.addswitch ('s%d' % (datacenter+client+1))

"Python" questions about the format parameters of Python

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.