It's actually easy (as everything, you already understand, of course, but this one really is):
True and False are the only two values you can get from any logical expression, e.g.:
- Your name is Ashley. -> True
- It is the year 1912. -> False
- It is half past 2 AM here and I should really go to bed. -> True
- 1 == 1 -> True
- 1 + 1 == 3 -> False
- etc.
Now, if statement takes an logical expression and allows its block to be executed only in case that expression evaluates to True:
if <Your name is Ashley>:
<This block gets executed.>
The same applies to while loops. It will loop over and over again "while the condition (i.e. the logical expression) is evaluated as True" - that is why it is called "while"-loop. The same sentence in other words: While loop will stop right at the moment when the expression will evaluate as False - in case that expression will be always True, while will loop until the end of the Universe (or until the program crashes):
while <Your name is Ashley>:
<This block will be executed>
<over and over again>
<until you will eventually get renamed.>
And the last thing is for if url:. It is just a shorthand notation for if url != "" (i.e. if url is not an empty string), given that url is a string. There is such shorthand for each data type:
- boolean:
if variable != False
- number:
if variable != 0
- string:
if variable != ""
- list:
if variable != []
- etc.
answered
05 Mar '12, 20:45
Marek Bálint
4.7k●16●42●85