.replace("a" or "b")

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jul 3 20:29:26 EDT 2018

On Tue, 03 Jul 2018 07:52:42 +0400, Abdur-Rahmaan Janhangeer wrote:

> .replace("a" or "b")

Oh I *wish* Python accepted that syntax to mean what you thought it meant.

That's a common error: a surprising number of beginners are fooled by how 
close Python is to natural language and try writing things like:

   if x == 1 or 2:

Reading Python is sometimes close to reading English, but not *that* 

There is currently no way to tell str.replace to replace "either this, or 

Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

More information about the Python-list mailing list