Question: I'm trying to replace punctuation to space in a string. I searched the answer and tried them in my python 2.7, they show different results. 

```
s1=" merry's home, see a sign 'the-shop $on sale$ **go go!'"   #sample string

print s1.translate(string.maketrans("",""), string.punctuation) #way1

print s1.translate(None,string.punctuation)                     #way2

table=string.maketrans(string.punctuation,' '*len(string.punctuation))
print s1.translate(table)                                       #way3

```

it prints like this:

```
merrys home see a sign theshop on sale go go
merrys home see a sign theshop on sale go go
merry s home  see a sign  the shop  on sale    go go  

```

so what's the difference between these ways?

Answer: 
There isn't really a functional difference in the first two ... You're either passing an empty translation table (`string.maketrans("","")`) or you're telling python to skip the translation step (`None`). After the translation, you're removing all punctuation since you pass `string.punctionat` as the characters that should be deleted. If I were a betting man, I'd bet that the `None` version would be slightly more performant, but you can `timeit` to find out...

The last example creates a translation table to map all punctuation to a space and doesn't delete anything. This is why the last example has a bunch of extra spaces in it.
The documentation for `translate` specifies [`str.translate(table[, deletechars])`](https://docs.python.org/2/library/stdtypes.html#str.translate)

> 
> Return a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation 
> 
> 
> 

cont

> 
> set the table argument to `None` for translations that only delete characters
> 
> 
> 

```
print s1.translate(string.maketrans("",""), string.punctuation)

```

In this case you delete all punctuation and replace empty strings with empty strings 

```
print s1.translate(None,string.punctuation)

```

In this case you're simply removing all punctuation.

```
table=string.maketrans(string.punctuation,' '*len(string.punctuation))
print s1.translate(table)

```

In this case you create a translation table that replaces punctuation with empty spaces and then translate.

The difference between the first and second is, as mgilson stated, in performance, the `None` case does indeed go a bit faster:

```
%timeit s1.translate(string.maketrans("",""), string.punctuation) #way1
The slowest run took 4.70 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 1.27 µs per loop

%timeit s1.translate(None, string.punctuation) #way1
The slowest run took 11.41 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 627 ns per loop

```

The third is a completely different application of translate.