0

print(type((lambda x, y, z: int((x + y + z)/3))(10, 11, 12)))

In the above code, I have used int() annotation but as per the python documentation, lambda functions cannot contain annotations. Then why am I not getting any error when using an annotation?

13
  • 2
    I see no type annotations here. Commented Sep 1, 2023 at 13:03
  • Isn't int an annotation? I even asked ChatGPT before posting question. It said it is an annotation Commented Sep 1, 2023 at 13:04
  • The int in your lambda is part of the expression it evaluates when called: It computes something with x,y and z and passes the result to int() to return an integer result at the end. Commented Sep 1, 2023 at 13:06
  • 1
    In your code you are not using int as a type annotation. You're using to to create an int-type object initialised with a value supplied within the brackets. Commented Sep 1, 2023 at 13:20
  • 1
    ChatGPT is unreliable as a fact checking tool to say the least, and it can be wildly inconsistent. The int keyword CAN be used to type annotate but it is NOT used as a type annotation here, it is used as a function to cast the parameter to the int type. Commented Sep 1, 2023 at 13:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.