r/Python • • Mar 03 '16

Top 30 Mind Bending Python Interview Questions

https://intellipaat.com/interview-question/python-interview-questions/
0 Upvotes

8 comments sorted by

5

u/Poffey21 Mar 03 '16

Advertisement for training services. No question was mind bending.

2

u/[deleted] Mar 03 '16 edited Mar 03 '16

Or even right. 6 built in types? Lol.

  • object

  • type

  • Exception

  • genexp -- (x for x in things)

  • range/xrange (depends on if you're 3/2)

  • bytearray, memoryview and bytes in Python 3

  • Unicode in Python 2

  • map, filter are classes in 3

  • float, int and complex are distinct types as well -- add long if you're Py2.

That's just the few in builtin I thought of that were missing.

Also depends on the definition of "builtin" as well.

2

u/notspartanono Mar 03 '16

So wrong:

def cmp(intellipaatlist1, intellipaatlist2):
    for val in intellipaatlist1:
        if val in intellipaatlist2:
            return True
    return False

WTF.

2

u/heptara Mar 04 '16

The answers to many of these are wrong. This site is just spam, or possibly harmful to learners.

1

u/[deleted] Mar 03 '16 edited Mar 03 '16

Here's a mind bender...

def foo():
    a = []
    a.extend([a] for _ in range(10))
    del a

Why does this fail with a syntax error in Python 2?

Edit: bracketed too much.

2

u/[deleted] Mar 03 '16

it doesn't

1

u/[deleted] Mar 03 '16

...fuck, I always remember that wrong. Fixed now.

1

u/TomBombadildozer Mar 03 '16

Mind bending numbing?