Admin Admin
ذكر عدد المساهمات : 23 نقاط : 10538 تاريخ الميلاد : 04/01/1988 العمر : 36 الموقع : Palestine(Hebron-Nablus)x العمل/الترفيه : Computer Engineering المزاج : good
| موضوع: assert -statement in python الإثنين يوليو 02, 2012 3:12 am | |
| There is an even more advanced feature of the assert statement. If the expression evaluates to a class, that class is used instead of AssertionError. This is not widely used, and depends on elements of the language we haven't covered yet
Here's a typical example
max= 0 if a < b: max= b if b < a: max= a assert (max == a or max == b) and max >= a and max >= b If the assertion condition is true, the program continues. If the assertion condition is false, the program raises an AssertionError exception and stops, showing the line where the problem was found
Run this program with a equal to b and not equal to zero; it will raise the AssertionError exception. Clearly, the if statements don't set max to the largest of a and b when a = b. There is a problem in the if statements, and the presence of the problem is revealed by the assertion | |
|