Python learning "7th": string concatenation

Source: Internet
Author: User

1. Formatted character with%s,%d,%f floating-point number

%s stands for formatted string, S is string meaning

msg = ' My name is%s '% "xiaoxing"
Print (msg)
Operation Result:
My name is xiaoxing

%d represents integer data int
msg = ' My name is%s,age:%d '% ("xiaoxing", 22)
Print (msg)
Operation Result:
My name is xiaoxing,age:22

%f representing floating-point numbers
Tp_1 = "annual interest rate is%f"%23.123456789
Print (tp_1)
Operation Result:
Annual interest rate is 23.123457
Rounding by default, six decimal places reserved

Tp_1 = "annual interest rate is%.2f"%23.123456789
Print (tp_1)
Operation Result:
Annual interest rate is 23.12
You can control the number of decimal digits left after rounding by. 2


format string
Http://www.cnblogs.com/wupeiqi/articles/5484747.html

Python learning "7th": string concatenation

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.