Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

PythonPr's tweet image. Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

Answer: c) True The infinity trap! › x = float('inf') is Python's infinity value › x > 100.0? Yes, infinity is greater than any number › isinstance(x, float)? Yes, inf is a float type › True and True = True For beginners: float('inf') and float('-inf') are valid…


Stream, call, game, and work in even the most remote locations. Order online in minutes


The correct answer is (c) True. Explanation The first line of code, x = float('inf'), assigns the floating-point representation of positive infinity to the variable x. The next line, y = (x > 100.0) and isinstance(x, float), evaluates a boolean expression.


>>> x=float("inf") >>> print(type(x)) <class 'float'> >>> x=str("inf") >>> print(type(x)) <class 'str'> >>> x=int("inf") Traceback (most recent call last): File "<python-input-4>", line 1, in <module> x=int("inf") ValueError: invalid literal for int() with base 10: 'inf'


C. Infinity is cast to float type...with that, RHS of 2nd statement evaluates to True.


Erro bec, inf is string can't be convert to float


True inf => infinity (x > 100.0)and isinstance(x, float) => Both conditions are met, hence True


Start your journey in simulated trading with FTMO, backed by 10 years of experience.


United States 趨勢
Loading...

Something went wrong.


Something went wrong.