Python for Absolute Beginners Transcripts
Chapter: Code that interacts with users
Lecture: Concept: Truthiness

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw the values that go into the if statement or elif statement or even the While statement have to evaluate to True or False.
0:09 So let's talk about this idea of truthyness. That maybe sounds like a weird word that doesn't quite make sense
0:16 but the idea is that different types of data can say for certain values I want you as far as the execution goes as far as the conditional blocks to go
0:25 we treat this is True and this is False. So for example if you have just have the word False well then obviously that's False
0:31 that is what the definition of False is in the programming language. But if you have a list and it has no data in it well then that's considered False
0:39 but if it has like one, one, and seven. It has some data in it then it's True. if you have something called a dictionary
0:46 or a set those are the same kind of rules. if you have a string well empty strings are False but non empty strings like "Hello"
0:54 that's a True statement. So this is a little bit of a weird idea at first the idea is instead of trying to come up with some
1:00 kind of test like is the length of the number of items in the list equal to 0, yes or no? You can just say if the list so it simplifies these tests.
1:10 Also for numbers if there's 0 that's False otherwise they're True and then none is a way to say this variable has no value at the moment.
1:19 That's also False. if it's not one of these things in the list then it's True. So we'll see an example of this in just a second
1:26 but this is leveraged all over Python if you've got numbers you've got collections you've got strings, very often the way you test
1:34 whether they're empty or not or their have decent values in them or not is to just do if the variable, carry on.


Talk Python's Mastodon Michael Kennedy's Mastodon