How many bytes does a string have
python
Solution
import sys
sys.getsizeof(s)
# getsizeof(object, default) -> int
# Return the size of object in bytes.
But actually you need to know its represented length, so something like `len(s)` should be enough.
Problem
Is there some function which will tell me how many bytes does a string occupy in memory? I need to set a size of a socket buffer in order to transfer the whole string at once.