🌐
LearnPython.com
learnpython.com › blog › python-string-formatting
Python’s String format() Cheat Sheet | LearnPython.com
Maybe we need to ensure the resulting strings align nicely. We definitely need to ensure that the tip percentage, currently stored as a decimal, is output as a percentage. To do that (and more), we need to use formatting modifiers as part of the Python formatting mini-language.
🌐
Python Cheat Sheet
pythoncheatsheet.org › home › string formatting
Python String Formatting - Python Cheat Sheet
If your are using Python 3.6+, string f-strings are the recommended way to format strings.
Discussions

Does anyone have a concise cheat sheet for f string formatting with numbers
Here's what I have as a reference. Basically a summary of the Format Specification Mini-Language . This would all go after a : in the f-string curly braces. So if you want a float with 2 decimal place precision, with * as fill and right aligned in a field width of 10 characters you'd do f"{val:*>10.2f}" [[fill]align][sign][#][0][minimumwidth][.precision][type] Fill: Add a character to fill with. Must be followed by Align flag. Align: '<' - Forces the field to be left-aligned within the available space (This is the default.) '>' - Forces the field to be right-aligned within the available space. '=' - Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form '+000000120'. This alignment option is only valid for numeric types. '^' - Forces the field to be centered within the available space. Sign: '+' - indicates that a sign should be used for both positive as well as negative numbers '-' - indicates that a sign should be used only for negative numbers (this is the default behavior) ' ' - indicates that a leading space should be used on positive numbers #: Flags alternate numbering formats; binary, octal, and hexadecimal output will be prefixed with '0b', '0o', and '0x', respectively. 0: Zero-padding. Equivalent to fill '=' and character of '0' Minimumwidth: Min width of the field. Precision: Decimal places for floats or max field size for non-numeric types. Type: Integers: 'b' - Binary. Outputs the number in base 2. 'c' - Character. Converts the integer to the corresponding Unicode character before printing. 'd' - Decimal Integer. Outputs the number in base 10. 'o' - Octal format. Outputs the number in base 8. 'x' - Hex format. Outputs the number in base 16, using lower- case letters for the digits above 9. 'X' - Hex format. Outputs the number in base 16, using upper- case letters for the digits above 9. 'n' - Number. This is the same as 'd', except that it uses the current locale setting to insert the appropriate number separator characters. '' (None) - the same as 'd' Floats: 'e' - Exponent notation. Prints the number in scientific notation using the letter 'e' to indicate the exponent. 'E' - Exponent notation. Same as 'e' except it converts the number to uppercase. 'f' - Fixed point. Displays the number as a fixed-point number. 'F' - Fixed point. Same as 'f' except it converts the number to uppercase. 'g' - General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to 'e' exponent notation. 'G' - General format. Same as 'g' except switches to 'E' if the number gets to large. 'n' - Number. This is the same as 'g', except that it uses the current locale setting to insert the appropriate number separator characters. '%' - Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. '' (None) - similar to 'g', except that it prints at least one digit after the decimal point. More on reddit.com
🌐 r/learnpython
5
3
February 2, 2022
The Only Python Cheat Sheet You Will Ever Need
Numeroc Type Mapping Type: Dictionary (dic) Looks like a few mistakes on the README. I don’t see them in the pdf. At least this is maybe evidence your cheat sheet isn’t more AI slop. More on reddit.com
🌐 r/Python
8
0
July 26, 2025
Python F-Strings Number Formatting Cheat Sheet
🌐 r/Python
2
82
August 12, 2022
python cheat sheet

X inY minutes is a great resource for quickly looking up the basics.

More on reddit.com
🌐 r/learnpython
25
92
November 2, 2015
🌐
Python Morsels
pythonmorsels.com › string-formatting
Python f-string tips & cheat sheets - Python Morsels
April 12, 2022 - Trey Hunner April 12, 2022 13 min read Python 3.10—3.14 ... This is a cheat sheet to string formatting in Python with explanations of each "cheat".
🌐
Codecademy
codecademy.com › learn › learn-python-3 › modules › learn-python3-strings › cheatsheet
Learn Python 3: Strings Cheatsheet | Codecademy
The Python string method .format() replaces empty brace ({}) placeholders in the string with its arguments.
🌐
Cheatography
cheatography.com › mutanclan › cheat-sheets › python-string-formatting
python string formatting Cheat Sheet by mutanclan - Download free from Cheatography - Cheatography.com: Cheat Sheets For Every Occasion
Python Cheat Sheets · python string formatting with call to .format() development python string format · 2 Pages · https://cheatography.com/mutanclan/cheat-sheets/python-string-formatting/ //media.cheatography.com/storage/thumb/mutanclan_python-string-formatting.750.jpg ·
Rating: 4 ​ - ​ 2 votes
🌐
Kapeli
kapeli.com › cheat_sheets › Python_Format_Strings.docset › Contents › Resources › Documents › index
Python Format Strings - Dash Cheat Sheets - Kapeli
Python Format Strings cheat sheet for Dash - String formatting, f-strings, and format() method reference. Download Dash for macOS to access this and other cheat sheets offline.
🌐
Cheatography
cheatography.com › gaston › cheat-sheets › python-string-formatting
Python String Formatting Cheat Sheet by Gaston - Download free from Cheatography - Cheatography.com: Cheat Sheets For Every Occasion
https://cheatography.com/gaston/cheat-sheets/python-string-formatting/ //media.cheatography.com/storage/thumb/gaston_python-string-formatting.750.jpg · PDF (recommended) PDF (4 pages) Alternative Downloads · PDF (black and white) LaTeX · Your Download Will Begin Automatically in 12 Seconds.
🌐
GitHub
github.com › ulope › pyformat.info
GitHub - ulope/pyformat.info: Single page cheat-sheet about Python string formatting · GitHub
With this project @ulope and @zerok wanted to document Python's awesome string formatting system with practical examples.
Author: ulope
Find elsewhere
🌐
DEV Community
dev.to › amohgodwin › f-strings-the-ultimate-cheatsheet-for-python-string-formatting-3cn
F-Strings: The Ultimate Cheatsheet for Python String Formatting - DEV Community
July 13, 2025 - You create an f-string by prefixing the string with the letter f or F. ... folder = "/home/user/john/movies" filename = "Big Buck Bunny.mp4" print(f"The folder name is '{folder}' and the filename is '{filename}'.") The output for both examples ...
🌐
Medium
medium.com › analytics-vidhya › string-reference-cheat-sheet-for-python-ce4958235ad5
String Reference Cheat Sheet For Python | by Dhirendra Patil | Analytics Vidhya | Medium
February 10, 2020 - This feature was added in Python 3.6 and isn’t used a lot yet. Again, it’s included here in case you run into it in the future, but it’s not needed for this or any upcoming courses. A formatted string literal or f-string is a string that starts with ‘f’ or ‘F’ before the quotes.
🌐
Fstring
fstring.help › cheat
Python f-string cheat sheet
These format specifications work on strings (str) and most other types (any type that doesn't specify its own custom format specifications).
🌐
Python
wiki.python.org › moin › FormatReference
FormatReference - Python Wiki
April 18, 2014 - Formatting Cheat Sheet (string.format): "{" [field_name] ["!" conversion] [":" format_spec] "}" / "r"|"s" \ / (r)epr (s)tr \ arg_name \ | ("." attribute_name | "[" element_index "]")* \ | | | \ | identifier integer | index_string | | (quotes | [identifier not required) | |integer] | | _________________________________________________________/ \________ / \ ":" [[fill]align][sign][#][0][width][,][.precision][type] [default]--> < left + | | (int) (int) b base 2 [default --> > right [-] | | c character for ^ center " " | \ d base 10 numbers] = | `zero padding e exponent (e) | E exponent (E) use 0
🌐
Medium
khemlall-mangal.medium.com › formatting-strings-cheat-sheet-3c17945276b0
Formatting Strings Cheat Sheet. Old string formatting (Optional) | by Khemlall Mangal | Medium
May 7, 2022 - “base string with %d and %d placeholders” % (value1, value2) To replace more than one value, the values need to be written between parentheses. The formatting expression needs to match the value type.
Top answer
1 of 2
3
Here's what I have as a reference. Basically a summary of the Format Specification Mini-Language . This would all go after a : in the f-string curly braces. So if you want a float with 2 decimal place precision, with * as fill and right aligned in a field width of 10 characters you'd do f"{val:*>10.2f}" [[fill]align][sign][#][0][minimumwidth][.precision][type] Fill: Add a character to fill with. Must be followed by Align flag. Align: '<' - Forces the field to be left-aligned within the available space (This is the default.) '>' - Forces the field to be right-aligned within the available space. '=' - Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form '+000000120'. This alignment option is only valid for numeric types. '^' - Forces the field to be centered within the available space. Sign: '+' - indicates that a sign should be used for both positive as well as negative numbers '-' - indicates that a sign should be used only for negative numbers (this is the default behavior) ' ' - indicates that a leading space should be used on positive numbers #: Flags alternate numbering formats; binary, octal, and hexadecimal output will be prefixed with '0b', '0o', and '0x', respectively. 0: Zero-padding. Equivalent to fill '=' and character of '0' Minimumwidth: Min width of the field. Precision: Decimal places for floats or max field size for non-numeric types. Type: Integers: 'b' - Binary. Outputs the number in base 2. 'c' - Character. Converts the integer to the corresponding Unicode character before printing. 'd' - Decimal Integer. Outputs the number in base 10. 'o' - Octal format. Outputs the number in base 8. 'x' - Hex format. Outputs the number in base 16, using lower- case letters for the digits above 9. 'X' - Hex format. Outputs the number in base 16, using upper- case letters for the digits above 9. 'n' - Number. This is the same as 'd', except that it uses the current locale setting to insert the appropriate number separator characters. '' (None) - the same as 'd' Floats: 'e' - Exponent notation. Prints the number in scientific notation using the letter 'e' to indicate the exponent. 'E' - Exponent notation. Same as 'e' except it converts the number to uppercase. 'f' - Fixed point. Displays the number as a fixed-point number. 'F' - Fixed point. Same as 'f' except it converts the number to uppercase. 'g' - General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to 'e' exponent notation. 'G' - General format. Same as 'g' except switches to 'E' if the number gets to large. 'n' - Number. This is the same as 'g', except that it uses the current locale setting to insert the appropriate number separator characters. '%' - Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. '' (None) - similar to 'g', except that it prints at least one digit after the decimal point.
2 of 2
1
A cheat sheet for f-string would be too short and kind of useless since f-string are super simple. If you want to put a number just do it. Ex. name: str = "Albus Dumbledore" age: int = 116 print(f"Name: {name}, Age: {age}") As you can see, I simply put age (which is an int) inside 2 brackets in the string (don't forget the f) and let Python do it's magic. (If you want you can use the example above as your cheat sheet)
🌐
GitHub
gist.github.com › draganHR › aa1a70a190386ef5ce71
Cheat sheet for "new style" string formatting in Python 2.6. · GitHub
It is modified version of examples from http://pyformat.info/ Difference is that simplest sytaxt ( '{}'.format('foo') ) does not work in Python 2.6 and you need to specify value index for each value ( '{0}'.format('foo') ). ... data = { 'first': 'Hodor', 'last': 'Hodor!', } '{first} {last}'.format(**data) '{first} {last}'.format(first="Hodor", last="Hodor!") ... person = { 'first': 'Jean-Luc', 'last': 'Picard', } '{p[first]} {p[last]}'.format(p=person) data = [4, 8, 15, 16, 23, 42] '{d[4]} {d[5]}'.format(d=data) class Plant(object): type = "tree" '{p.type}'.format(p=Plant()) class Plant(object): type = "tree" kinds = [{ 'name': "oak", }, { 'name': "maple" }] '{p.type}: {p.kinds[0][name]}'.format(p=Plant())
🌐
Cheatography
cheatography.com › brianallan › cheat-sheets › python-f-strings-basics › pdf pdf
Python F-Strings Basics Cheat Sheet by BrianAllan
Python F-Strings Basics Cheat Sheet ... used by f-string must have different kind of quotes · f'She has {pet['​cat​s']}.'  · Format​ting: Fill, Align, Width ·...
🌐
Cheatography
cheatography.com › maschmidt2 › cheat-sheets › python-format-string-syntax
Python Format String Syntax Cheat Sheet by maschmidt2 - Download free from Cheatography - Cheatography.com: Cheat Sheets For Every Occasion
Python Cheat Sheets · Python Format String Syntax · This is a draft cheat sheet. It is a work in progress and is not finished yet. python · 1 Page · https://cheatography.com/maschmidt2/cheat-sheets/python-format-string-syntax/ //media.cheatography.com/storage/thumb/maschmidt2_python-format-string-syntax.750.jpg ·
🌐
GitHub
gist.github.com › 51f3102bff83a08aa4003e69b546098a
Python cheatsheet from https://github.com/codingforentrepreneurs/30-Days-of-Python/blob/3d9f13df2d64efd6b2873bc00bd5f22a185ddee7/PythonCheatSheet.md · GitHub
text_length = len("Some string, with some stuff.") print(text_length) 29 text = "Some other length" text_length2 = len(text) print(text_length2) 17 ... text = "This is {variable_a} formatted string".format(variable_a="variable based") print(text) text = "This is another {variable_a} formatted string with \ multiple variables like {a} {b} {c}.".format( variable_a="variable based", a="some random", b="replacement", c="text") print(text) text = """So, {name}, the best part is formated strings you don't have to order it.