Byte size of string
Returns the length of a string in bytes.
- Use
str.encode()
to encode the given string and return its length.
def byte_size(s): return len(s.encode('utf-8')) byte_size('😀') # 4 byte_size('Hello World') # 11
Returns the length of a string in bytes.
str.encode()
to encode the given string and return its length.def byte_size(s): return len(s.encode('utf-8')) byte_size('😀') # 4 byte_size('Hello World') # 11
Pads a string on both sides with the specified character, if it's shorter than the specified length.
Pads a given number to the specified length.
Python's f-strings can do a lot more than you might expect. Learn a few useful tips and tricks in this quick guide.
Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components.