Python string formatting output method analysis, python string

Source: Internet
Author: User

Python string formatting output method analysis, python string

This document describes how to format and output Python strings. We will share this with you for your reference. The details are as follows:

There are three ways to format and construct a string:

1-tuple placeholder

M = 'python' astr = 'I love % s' % mprint astr

2 string format Method

M = 'python' astr = "I love {python}". format (python = m) print astr

3. format the string in the dictionary.

M = 'python' astr = "I love % (python) s" % {'python': m} print astr

You can select an appropriate method based on your actual situation. We recommend that you use the string format method or dictionary placeholder formatting because it is not affected by the parameter location, you only need to have the same parameter name.

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.