Talking about placeholders in python, talking about python

Source: Internet
Author: User

Talking about placeholders in python, talking about python

Placeholder, as its name implies, is the symbol inserted into the output. We can understand it as booking a hotel. When we tell the hotel, there will be a reservation in the hotel system. Although we haven't gone yet, our customers will be behind us.

There are three common placeholders:

1.% d integer placeholder

>>> 'I scored % d' % 20' I scored 20 '>>>' I scored % d '% 20.5; I scored 20 points '> "I scored % d, improved % d" % (50, 10) "I scored 50 points, improved by 10 points"

% D can only hold integers. Even if the original number is a floating point number, it is forcibly converted to an integer.

2.% f floating point placeholder

>>> "I took % f" % 66.666 "I took 66.666000" >>> 'I took % F' % 66' I took 66.000000 '>>>" I passed % f, %. 2f "% (66, 12.369)" I took 66.000000 exams and improved by 12.36"

% F can only hold floating-point numbers, while %. xf is precise to the x-digit after the decimal point.

3.% s string placeholder

>>> '% S' % Ture' >>>' % s, % s' % (123, abc) '2017, abc'

% S placeholder string, with the maximum number of applications.


The above is all the content about placeholders in python in this article. I hope it will help you. If you are interested, you can continue to refer to this site: Share the verification code Image Code on the Python web, crawl a Python crawler instance to get a funny Website Section, and use the trigonometric function of getting started with Python to [add to favorites, if you have any questions, you can leave a message at any time. The editor will reply to you in a timely manner. Thank you for your support!

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: 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.