How to use format in python

coldplay.xixi
Release: 2023-01-03 09:28:43
Original
195331 people have browsed it

How to use format in python: [format():] Replace the traditional [%] with [{}] to achieve formatted output. The code is ['numbers {1}{2} and { 0}'.format("123",456,'789')].

How to use format in python

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

How to use format in python:

format() formatted output

format(): replace the traditional % with {} Realize formatted output

Common usage of format():

is actually the content after format(), filled in the curly brackets (you can press the position, or press Variables)

'数字{1}{2}和{0}'.format("123",456,'789') >>>'数字456789和123'
Copy after login
#这里注意有两层大括号,输出的结果只有一层大括号 '数字{{{1}{2}}}和{0}'.format("123",456,'789') >>>'数字{456789}和123'
Copy after login
#允许一个参数用两次 '{1}{0}{1}岁'.format('jc',22) >>>'22jc22岁'
Copy after login
#可以通过添加关键字参数 '{name}{age}岁'.format(age=22,name='jc') >>>'jc22岁'
Copy after login

Related free learning recommendations:python video tutorial

The above is the detailed content of How to use format in python. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!