Note Raw strings treat backslashes as literal characters. Essential for regex patterns and Windows paths. A raw string cannot end with an odd number of backslashes.
raw stringescape backslashregex stringwindows path
Encode & Decode
Syntax
str.encode(encoding)bytes.decode(encoding)
Example
text ="caf\u00e9"
encoded = text.encode("utf-8")print(encoded)print(encoded.decode("utf-8"))
Output
b'caf\xc3\xa9'
caf\u00e9
Note UTF-8 is the default encoding. Use errors='ignore' or errors='replace' to handle characters that cannot be encoded in the target encoding.
encode stringdecode bytesutf-8bytes to stringstring to bytes
Join & Split
Syntax
separator.join(iterable)str.split(separator)
Example
words =["Python","is","great"]
sentence =" ".join(words)print(sentence)
csv_row ="alice,30,engineer"
fields = csv_row.split(",")print(fields)
Output
Python is great
['alice', '30', 'engineer']
Note split() with no arguments splits on any whitespace and removes empty strings. split(',') keeps empty strings between consecutive delimiters.