Python format() function
Halimbawa
Formatihin ang bilang na 0.5 bilang porsyento:
x = format(0.5, '%')
Run Halimbawa
Paglilinaw at Paggamit
format() function ay isang pinaghalong nilalaman sa isang tinukoy na format.
Syntax
format(value, format)
Parameter Value
Parameter |
Description |
value |
Any Format Value. |
format |
Ang Format Na Gustong Formatin Ng Iyong Value.
Legal Values:
- '<' - Left Align The Result (Within Available Space)
- '>' - Right Align The Result (Within Available Space)
- '^' - Center Align The Result (Within Available Space)
- '=' - Place The Symbol On The Left Most Side
- '+' - Use Plus Sign To Indicate Whether The Result Is Positive Or Negative
- '-' - Negative Sign Only For Negative Values
- ' ' - Use Space Before Positive Number
- ',' - Use Comma As Thousand Separator
- '_' - Use Underscore As Thousand Separator
- 'b' - Binary Format
- 'c' - Convert Value To Corresponding Unicode Character
- 'd' - Decimal Format
- 'e' - Scientific Format, Using Lower Case e
- 'E' - Scientific Format, Using Upper Case E
- 'f' - Fixed Number Format
- 'F' - Fixed Number Format, Upper Case
- 'g' - General Format
- 'G' - General Format (Uses Upper Case E for Scientific Notation)
- 'o' - Octal Format
- 'x' - Hexadecimal Format, Lower Case
- 'X' - Hexadecimal Format, Upper Case
- 'n' - Number Format
- '%' - Hundred Percent Format
|
Higit Na Halimbawa
Halimbawa
Format ng 255 Bilang Hexadecimal Value:
x = format(255, 'x')
Run Halimbawa