Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 4: Journal app and file I/O
Lecture: Complex conditionals and, or, and not

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's come back to our event loop for a moment. So when I run this app, I can list the items, and I can an add an entry and hit exit,
0:09 but if I hit like enter, you can see I get kind of this weird like hey we don't understand nothing, maybe I'd like an empty entry that just mean
0:17 hey let's just exit, save and exit, so we can change our code really quickly here, first of all, let me change this to be something
0:24 other than a non-existent empty pointer, Ok? We want to come up here and we want to have a complex conditional that says
0:33 when the command is not the x and it's not empty so in many languages, you use symbols like the && or double pipe to say and and or,
0:45 Python we just say and or or, ok, so if we want to say the command is not equal to x, and the command has some value in it,
0:57 I could say like it's not equal to none, or the length is greater than 0, or something like this,
1:03 but in Python remember the truthiness of collections and strings are collections are if they are not empty then they are true,
1:11 and if they are empty then they are false. Maybe that's a bad choice of words of being empty like this. Ok, so this will almost work if we run this,
1:20 and when I say list then enter, it says we don't understand that and then boom, it exits. So we need to add another bit down here,
1:27 say if the command is not X, and there is some sort of command entered here, right, which is not empty, then save this error.
1:38 If we wanted to say it's not X and there's nothing in here we would say and not command. Right, so there is ways to combine this with parenthesis,
1:46 and all the boolean logic you can do in regular programming. All right, so here let's list the entries, and hit enter boom, goodbye.

Talk Python's Mastodon Michael Kennedy's Mastodon