|What is a “gotcha”?The word “gotcha” started out as the expression “Got you!” This is something that someone who speaks idiomatic American English might say when he succeeds in playing a trick or prank on someone else. “I really got you with that trick!”
The expression “Got you!” is pronounced “Got ya!” or “Got cha!”.
Among computer programmers, a “gotcha” has become a term for a feature of a programming language that is likely to play tricks on you to display behavior that is different than what you expect.
Just as a fly or a mosquito can “bite” you, we say that a gotcha can “bite” you.
About this Page
This is a page devoted to Python “gotchas”. Python is a very clean and intuitive language, so it hasn’t got many gotchas, but it still has a few that often bite beginning Python programmers. My hope is that if you are warned in advance about these gotchas, you won’t be bit quite so hard!
Note that a gotcha isn’t necessarily a problem in the language itself. Rather, it is a situation in which there is a mismatch between the programmer’s expections of how the language will work, and the way the language actually does work. Often, the source of a gotcha lies not in the language, but in the programmer. Part of what creates a programmer’s expectations is his own personal background. A programmer with a Windows or mainframe background, or a background in COBOL or the Algol-based family of languages (PL/1, Pascal, etc.), is especially prone to experiencing gotchas in Python, a language that evolved in a Unix environment and incorporates a number of conventions of the C family of programming languages (C, C++, Java).
If you’re such a programmer, don’t worry. There aren’t many Python gotchas. Keep learning Python. It is a great language, and you’ll soon come to love it.
Other posts about Python Gotchas
- Backslashes are escape characters
- Backslashes in Windows filenames
- Forgetting to code the parentheses in method calls
- Specifying mutable default arguments for a function or method
Lists of Python Gotchas
- Steve Ferg’s list of Python Gotchas.
- Hans Nowak’s list of Python Pitfalls.
- Mark Lutz’s instructions on what to do When Pythons Attack.