how to convert spaces to underlines in python string code example Example: python replace space with underscore mystring.replace(" ", "_")