Text formatting of Python basics

Source: Internet
Author: User
This article is mainly for you to share on the basis of Python text formatting, the method is very detailed, the need for friends can look

1.Python text formatting

In the version of Python 3.0, the input statement defaults to a string (even if the input number is treated as a string), and is coerced into a number: Age=int (Input ("Input your Age:"))
Python2.7 in input and raw_input:


Input in Python3.5, no raw_input function:

1.1 Method One

%s----Reference string, number%d----integer%f----floating point%x----hexadecimal integer
In the place where you need to format the%s instead, the end of the statement with a% (), the parentheses fill in the contents (strings quoted, separated by commas), if there is only one content, you can omit the parentheses.
Program:

Output:

2.2 Method Two


Floor,ceil function-rounding (e.g. 32.9 for 32.0 or 33.0)

Program:

Output:

Program:

Output:

Related recommendations:

Python Basic Tutorial file operations implement full-text or single-line substitution methods

Getting Started with Python basics-Blockchain

Python basic entry-level operations summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.