Python String Cheat Sheet

Posted : admin On 1/3/2022

Field Width and Alignment

(Above is the printable version of this cheat sheet) This Python cheat sheet will guide you through variables and data types, Strings, Lists, to eventually land at the fundamental package for scientific computing with Python, Numpy. Whether you’re working with string methods or built-in functions in Python, this Cheat Sheet helps you program the correct order for the operation so you achieve the correct result. This cheat sheet is designed to give you a handy resource for common Python data types, Python operators, and Python functions. It includes Python data types, operators, special characters, f-strings, and functions for working with robots.

'hey {:10}'.format('hello')


Output: 0000000002


Output: *************text*************

Member and Element Access

'{0}, {1}, {2}'.format(1, 2, 3)

Output: 1, 2, 3

'{}, {}, {}'.format(1, 2, 3)

Implicit positional arguments (2.7 and above only)

'{value1}, {value2}, {value2}'.format(value1=1, value2=2, value3=3)

Access keyword arguments by name

'{[1]}'.format(['first', 'second', 'third'])

Access element by index


Access element attribute

'{[name]}'.format({'name': 'something'})

Access element by key

Python String Function Cheat Sheet

Numerical Representation



Output: 64


Output: D9F


Output: 0x64


Output: 1100100


Output: d


Output: 100


Output: 1,000,000


Output: 144


Like d, but uses locale information for separators


Exponent notation


Exponent notation (capital 'E')


Fixed point


General format





Python String Cheat Sheet


Python String Cheat Sheet

Python Basics Cheat Sheet


Output: 'string'


Output: 1.53438987