QUIZ: How well do you know Python?

Over in one of the Ideas threads, I put the theory that very few people know absolutely everything about Python. So here’s a bit of a quiz to try.

Contains some esoterica.

This is a for-fun quiz, and please try your best to answer from memory without any reference to documentation or testing in the REPL.

Errors in the quiz? Please drop me a DM. It’s a bit fiddly to set things up and I might very well have made a mistake somewhere.

Want to brag about your score? Post it here!

21 Likes

16/20 here :smiley: Nice quizz!

Looks like all questions with “multiple correct answers” only accept one, though.

4 Likes

Yeah, any of the correct answers will be accepted. They’re meant to be a bit easier.

I lost a point because you didn’t take PEP 758 into account >:-(

1 Like

I think what you’re really saying is that I made an error in saying that it’s for version 3.12-3.14, when 3.14 hasn’t been released yet. I should have said 3.13, since that actually exists. And actually, I tested most things out in 3.11 as well to be safe, so I’m going to update it to say 3.11-3.13.

Sorry for the point loss. That’s on me.

I felt obligated to take it because I was one of the people to like your previous post, but I did miserably. I choose to interpret this saying I only write nice idiomatic code, and so I’ve never needed to learn these dark esoteric details. :sweat_smile:

One note: somehow “Which of these is a valid integer literal?” is the only question that is listed as optional, I assume that was an accident.

2 Likes

Yep, that’s a legit interpretation! These are fairly gnarly specifics, though I would expect that many of us have run across at least one or two.

Ah, thanks, that is indeed unintended.

By the way, I don’t see people’s specific right and wrong answers, but I do have stats on which answers have been selected. By and large, people seem to be doing well; in most questions, the majority response is also the correct one. There are only two that are notably otherwise are the questions on integer and string literals.

For the integer literal, I got tricked by 0 vs O and didn’t pay close enough attention

For the string literal, I just actually didn’t know this obscure fact.

5 Likes

13/20.

Overall I am okay with the ones I didn’t get, because I genuinely did not know most of those, the one I did and still made a mistake was the f-string one, for which I didn’t want to spend the attention it needed. There are two cases I am slightly annoyed with:

First one, I got confused with 0 and O with Google’s font. Also I was extremely tempted. This, I am annoyed with myself.

The second one is more interesting. “Which of these is NOT a statement?” question tripped me up. One was blatantly wrong, but I didn’t choose that one, because if it were legal, it could be counted as a statement. I chose the one that is an expression. Although if the logic was “all expressions are statements”, then I got owned. Otherwise I think the wording could be improved.

Thanks for the nice quiz!

1 Like

Yeah, I can’t blame you; sadly, I don’t have much choice there. I wanted to use some monospaced (code) text in places, and had to make do with bold. I actually went through three or four different quiz sites before going with the Google form, because they either wanted money for anything more than ten responses a month, or just had too many ads, or something.

There is a very very strange subtlety here.

The yield keyword can be used in both statement and expression form.

7. Simple statements — Python 3.13.3 documentation

In the context of a larger expression, yield x is a valid expression, so (yield x) is indeed a statement-expression. However, due to a quirk of grammar, a stand-alone yield has to be its own type of statement. But, that’s a very VERY obscure subtlety, and the logic “any expression is a valid statement” is also a valid justification. One of the other three options is, in fact, not legal Python code (and thus definitely not a statement).

<3

I think it’s kinda fun :sweat_smile:

Regarding the subtlety, it is certainly very strange. I probably didn’t read that part of the docs very carefully! After reading your reply, I tried looking at AST dump of return 0 , return (yield 0), and yield 0. I got slightly more confused by the documentation of ast.Yield, which unequivocally calls it an expression.

Nice and tricky quiz. Got 13/20, woulda gotten 14 but I read one question the opposite way.

1 Like

15/20.

The arguments/parameters one I got wrong, not because I didn’t know the correct answer, but because I got muddled over which is an argument and which is a parameter!!! Must be time for me to go to bed… :zzz:

Nice quiz.

7 Likes

15/20

Questions that I got wrong:

  • Which of these is NOT a valid string literal?
  • Which of these is a valid integer literal?
  • Negative numbers are just WEIRD, they don’t make any sense! Which of these expressions will succeed?
  • Python has:
  • What will this print?

This was pretty fun! Thank you for making it :grinning_face_with_smiling_eyes:.

1 Like

Damn it. Those are exactly the two questions I got wrong. Nice quiz! Too bad the form doesn’t allow selection of multiple choices for questions that have multiple correct answers.

2 Likes

If you picked any one that was correct, you are considered correct. Those questions are meant to be a bit easier/more forgiving.

(And yes, there is one question where all four answers are correct.)

1 Like

One of these is not valid in a match block:

  1. case otherwise:
  2. case len(“spam”):
  3. case 1 | 2 | 3:
  4. case signal.SIGINT:
class len:
    v = "spam"
    __match_args__ = ("v",)
5 Likes

:smiley: I mean, technically yes… but by that token, you could shadow type and completely redefine the question about dunder methods, or any of the other things mentioned. Give yourself one bonus point for being technically correct, but score yourself out of 21 points.

1 Like

I got 18 out of 20, although a couple I just sort of went with my gut without thinking.

These kinds of things are fun, although I kind of prefer questions that edge a bit closer to practicality (like the one about “what output will this produce”). :slight_smile:

1 Like