tubeshowcase●1,151,788 videos♡ My collection 0
← Learn to Code

Learn to Code04:56

x to bool conversion in Python, C++, and C

mCoding ↗

From the creator

How to decide if a variable is truthy. How do Python, C++, and C decide if "if x" goes down the "true" path or "false" path? Whether you're a Python beginner or an expert Python user, you need to know the rules that are used. Conditionals don't just take conditions. In some languages, like Python and C++, you can put expressions that evaluate to arbitrary objects inside a conditional. In this video we go through the basic rules for when this is allowed in Python, C++, and C, and show the code that determines whether to treat your object like "true" or "false". We use Matt Godbolt's Compiler Explorer to look at the disassembled bytecode or assembly, and then we hunt down the CPython source code for what this bytecode means. This question is exactly the kind of thing that might show up in a Python coding interview, or C++ programming interview to test your knowledge of the language. ― mCoding with James Murphy (https://mcoding.io) ceval.c: https://github.com/python/cpython/blob/main/Python/ceval.c object.c: https://github.com/python/cpython/blob/main/Objects/object.c Compiler Explorer Python example: https://godbolt.org/z/cETPW8Tex Compiler Explorer C++ example: https://godbolt.org/z/na1hx86Pa Compiler Explorer C example: https://godbolt.org/z/r9Tj3xY4r SUPPORT ME ⭐ --------------------------------------------------- Patreon: https://patreon.com/mCoding Paypal: https://www.paypal.com/donate/?hosted_button_id=VJY5SLZ8BJHEE Other donations: https://mcoding.io/donate Top patr

Published 2021-07-17 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code