Python Types

String

my_string = "Hello World!"
lowercase_string = my_string.lower()

text3 = "123456"
print(f"'{text3}' is alphanumeric: {text3.isalnum()}")  # True
invalid_text1 = "Python 123"  # Contains a space
print(f"'{invalid_text1}' is alphanumeric: {invalid_text1.isalnum()}") # False

Format String

Aligning the text and specifying a width:

Replacing %+f, %-f, and % f and specifying a sign:

Float

Replacing %x and %o and converting the value to different bases:

Using the comma or the underscore as a digit group separator:

Expressing a percentage:

Using type-specific formatting:


Collections

See in Python Data Structure


Last updated