Methods

A collection of random possibly confusing and important python methods.

decode

  • purpose: converts bytes to a string
  • use cases: network data, binary files,
python
data = socket.recv(1024)  # Returns bytes
message = data.decode('utf-8')  # Convert to string

ord

ord short for ordinal which means position in sequential order

In python ord returns the ordinal position (numeric value) of a character.

Python
a = ord('A') # 65
# char converts back to character
char(a) # A