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

What does format in python mean?

silencement
Release: 2019-06-24 17:47:52
Original
42369 people have browsed it

What does format in python mean?

format function

This is a string formatting method, such as str.format().

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

The following shows two main usages:

(1) For example: the statement print("{:.2f}".format(3.1415926)), its output is 3.14, as can be seen The command is to preserve two decimal points.

(2) For example: the statement "{1} {0} {1}".format("hello", "world"), its output is 'world hello world', it can be seen that the format is They set the location.

Another example: the statement print '{} *'.format(j) indicates the value of the output variable j and the multiplication sign: j*. It can be seen that when used in a loop, a multiplication equation can be output.

Another example: The statement print "{} corresponds to the position {{0}}".format("runoob"), and its output is 'runoob The corresponding position is 0'.

The following table shows the various ways str.format() formats numbers:


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

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template