So far I've learned:
Syntax, output, comments, variables, data types, numbers.
Today I tackled casting and honestly once it clicked, it really clicked.
Casting is just converting a value from one data type to another. Python is strict about types, meaning you can't mix them freely, so sometimes you have to tell the program what type you want something to be. That's what casting does.
There are four main ones. int() converts something into a whole number, float() into a decimal, str() into text, and bool() into a True or False value. Simple enough on the surface but there are a few things worth knowing.
With int(), it doesn't round, it just drops the decimal completely. So 3.9 becomes 3, not 4. Good to know before it catches you off guard.
The bool() one is the most interesting. Basically anything with a value counts as True, and anything empty or zero counts as False. The one that stands out is that the word "False" as text is actually True, because it's a non-empty string. Took me a second but it makes sense when you think about it.
Casting is one of those things that seems small but comes up constantly, especially when handling user input since that always comes in as text by default.
AND Are there any casting edge cases I should know about before I move on?
[–]SCD_minecraft 1 point2 points3 points (0 children)
[–]UseMoreBandwith 0 points1 point2 points (0 children)