Home  >  Article  >  Backend Development  >  Python basics text formatting

Python basics text formatting

不言
不言Original
2018-04-02 09:10:482207browse

This article mainly shares with you about text formatting in Python basics. The method is also quite detailed. Friends in need can take a look

1.Python text formatting

In the Python 3.0 version, the input statement inputs a string by default (even if you enter a number, it will be treated as a string), and it is forced to be converted into a number: age=int(input("input your age:"))
Python2 .7 input and raw_input:
Python basics text formatting
Python basics text formatting
Python basics text formatting

##Python3 In input in .5, there is no raw_input function:


Python basics text formatting

1.1 Method 1

%s----Quote strings and numbers %d- ---Integer %f----Floating point number %x----Hexadecimal integer

Replace with %s in the position that needs to be formatted, add %() at the end of the statement, and fill in the content directly in the brackets (The string is quoted and separated by commas). If there is only one content, the brackets can be omitted.
Program:

Python basics text formattingOutput:

Python basics text formatting##2.2 Method 2

Python basics text formattingfloor, ceil function--rounding (such as 32.9 is taken as 32.0 or 33.0)
Program:


Python basics text formattingOutput:


Python basics text formattingProgram:


Python basics text formattingOutput:


Python basics text formattingRelated recommendations:

Python basic tutorial file operation method to achieve full text or single line replacement

PythonBasic Introduction--Blockchain

Python Basic Entry-Level Operation Summary

The above is the detailed content of Python basics text formatting. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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