Viewers: in countries Watching now:
Due to its power, simplicity, and complete object model, Python has become the scripting language of choice for many large organizations, including Google, Yahoo, and IBM. In Python 3 Essential Training, Bill Weinman demonstrates how to use Python 3 to create well-designed scripts and maintain existing projects. This course covers the basics of the language syntax and usage, as well as advanced features such as objects, generators, and exceptions. Example projects include a normalized database interface and a complete working CRUD application. Exercise files accompany the course.
Conditional execution in Python is handled with the If statement. So, let's go ahead and make a working copy of conditionals.py, call it conditionals-working.py, and we'll Open that up and start by just defining a couple of variables. a and b equals 0 and 1. If we want to just execute some code, if a is less than b, all we do is we type if a < b: print ('this is true').
Now, when I save that and run it, you see that 'this is true' got printed. So, this print statement executed, and the way this works is the if keyword introduces the conditional, and the expression here, a is less than b, and that could be any expression that evaluates to True or False and a colon introduces the suite of code and so this could be a suite of code. It could be a number of things, and that gets executed if this expression evaluates to true. If the expression does not evaluate to true - I'll just change this 0 to 1, and a is no longer less than b, save that and run it - then nothing happens at all.
So, if we want something different to happen, if the expression is false, then I can simply say else and a colon and another suite of code, it is not True. So, if I save that and run it, then we get that here it is not true, and if I make this 1 a 0 again, save and run, then we get 'this is true.' So, this expression can actually be any expression that evaluates to true or false, and so I could just actually put the word True there, and it'll be true, save and run, this is true, or I can put the word False there, and save and run, and we get, 'it is not true.' So, that is the if and else in Python.
If is a keyword, and then it's followed by any expression that evaluates true or false and a colon and then a suite of code, and the optional else will execute its suite of code, if the condition is false and not true.
Find answers to the most frequently asked questions about Python 3 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.