space replace with - in python code example Example 1: replacing spaces in a string python mystring.replace(" ", "_") Example 2: replace space with . pyhton mystring.replace(" ", "_")