replace space by underscore python string code example Example: python replace space with underscore mystring.replace(" ", "_")