Get the App
SLTechnology News&Howtos  ›  Development  › 

How to format% in python

Shulou Source: shulou.com Published: 2022-06-03 17:34:09 11月13日 Update

Editor to share with you how to achieve formatting in python, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In python, in addition to the format method, we can borrow symbols for formatting. The% symbol can format a string.

1. The internal% of the string represents the occupation of a specific format string.

2. The right side of the string is connected with the parameters to be formatted by%, which corresponds to the internal occupancy% one by one.

Inside the string,% s means to replace with a string,% d means to replace with an integer, how many% placeholders there are, and then corresponds to several variables or values one by one.

Example

> 'Hello,% s' world''Hello, world' > 'Hello,% s, total consumption% d yuan'% ('Xiao Ming', 1000000) 'Hello, Xiao Ming, total consumption of RMB 1000000' is all the contents of this article entitled "how to format% in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Format character string article one-to-one correspondence Hello content symbol Xiaoming consumption not much parameters variables right most instances integers methods more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Docker Shulou Information MySQL