Previous post: A detailed description of common formatted output characters for Python basicsHowever, sometimes we need to use more than a percentage of time, with this is very inconvenient, such as the number of errors% or one by one corresponding
Debug formatted output----based on C language 1. Using macro implementationsExample:#include #define ECHO_COLOR_NONE "\033[0;0m"#define ECHO_COLOR_GREEN "\033[0;32m"#define debug(fmt, args...)
Formatted output problems for numbersYou need to format the numbers and output them, and control the number of digits, alignment, thousand separators, and other details.Solution SolutionsWhen you format the output of a single number, you can use the
Usage
int printf (const char *format,[argument]);
Format for the output of the format parameter, defined as:
%[FLAGS][WIDTH][.PERC] [f| N|h|l]type
Specify the mode of data output, as follows:
1.type meanings are as follows:
D signed 10 binary
This example summarizes the formatted output usage in Python. Share to everyone for your reference, as follows:
Python has a total of two formatting output syntaxes.
One is similar to the C-language printf approach, called formatting Expression
>>
C language can use printf (),%f to achieve the format of floating point number output, with cout ...?The Iomanip is the I/O flow control header file, just like the formatted output of printf.Here are some common ones:Dec base is 10 equivalent to "%d"
The Iomanip is the I/O flow control header file, just like the formatted output in C. Here are some common: the DEC base is 10 equivalent to "%d" hex base 16 equivalent to "%x" Oct base 8 equivalent to "%o" Setfill (c) Set the fill character to
CommentsSingle line: #Multiple lines: 3 consecutive single or double quotes on top and bottom3 Quotes In addition to multiple lines of comment, you can also print more than one lineExample:msg = "name =" Alex Li "name2 = Nameprint (" My name is ",
I. variables:
Explanation: stores intermediate results of program operations for subsequent program calls.
1. The variable must contain numbers, letters, underscores, and any combination.2. The variable cannot start with a number.3. It cannot be a
1 #three ways to play format2Res1 ='{},{},{}'. Format ('Joker','male', 18)3 Print(RES1)#similar to placeholder4Res2 ='{1},{0},{1}'. Format ('Joker','male', 18)5 Print(Res2)#similar to list corner label lookups6Res3 ='{Name},{age},{sex}'. Format (sex=
Today, the program also does not remember the format of the output details ... = = simply tidy up.Python print formatted output.1. Print a stringPrint ("His name is%s"% ("Aviad"))Effect:2. Printing integersPrint ("He is%d years old"% (25))Effect:3.
formatted output for Java
A method to format the output requires a format string and a parameter list (arguments). The format string may include the determined text (fixed text) and one or more format specifiers (formatted specifier). Look at
Formatted output>>> ' hello,%s '% ' world '>>> ' hi,%s,you have $%d. ' (' Mike ', 100)%s string%d integers%f floating Point%x hexadecimal integerA, where formatted integers and floating-point numbers can also specify whether to complement 0 and the
What is formattingLook at the following code: 10 print("我今年%d岁"%age) age += 1 print("我今年%d岁"%age) age += 1 print("我今年%d岁"%age) ...In the program, you see this % operator, which is the formatted output in Python. 18 name =
The first thing to say is the formatted output of the C language, which is the printf and several variants of it (grep-e "v?"). (sn|s|f) printf "). Like these functions have a parameter Format,format can add some conversion instructions, let the
function DescriptionIn GCC programming, the character format output function that we commonly use is printf, in fact, GCC inherits the C language processing character has the powerful function style, it provides a series of formatted output function,
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.