Home > Backend Development > Python Tutorial > What does format mean in python

What does format mean in python

藏色散人
Release: 2019-06-24 10:02:20
Original
29678 people have browsed it

What does format mean in python

Starting from Python 2.6, a new function str.format() for formatting strings has been added, which enhances the function of string formatting.

The basic syntax is to replace the previous % with {} and :.

The format function can accept unlimited parameters, and the positions do not need to be in order.

Example

>>>"{} {}".format("hello", "world")    # 不设置指定位置,按默认顺序
'hello world'
 
>>> "{0} {1}".format("hello", "world")  # 设置指定位置
'hello world'
 
>>> "{1} {0} {1}".format("hello", "world")  # 设置指定位置
'world hello world'
Copy after login

Related recommendations: "Python Tutorial"

The above is the detailed content of What does format mean in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
format
From 1970-01-01 08:00:00
0
0
0
How to format date in JavaScript?
From 1970-01-01 08:00:00
0
0
0
How to format date in JavaScript?
From 1970-01-01 08:00:00
0
0
0
Format date string
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template