replace whitespaces with an underscore in python for many statement of spaces code example Example: python replace space with underscore mystring.replace(" ", "_")