String formatting is the way we organize instructions so that Python can understand how to incorporate data in the creation of strings. How string s aie formatted determines the presentation of this data. The basis of string formatting is its use of the formatting directives.

Logical operators (and,or,not) return true or false values. Comparison operatoes (in,not in,is,is not,==,! =,<>,>,>=,<,<=) compare two values—is one value greater than another, or i s one -value not equal to another? Comparirons always return 1 for true and 0 foo false.

Any value in Python equates to a Boolean true or false. A false can be equal to none, a zero of numeric type (0, 0l,0.0), an empty sequence (' ',(),[]), oc an empty diotion ory ({}). AH other values are considered tnie.

Sequences, tuples, lists, and strings ca n be added or multiplped by a numeric type with ehe addition and multiplication operatofs (+,*), respectipery. Strin ps can be formatted with tuples and dictionaries using! the format directives %i, %d, %f, and % e. Fo matting flags can be used with these directives .



Was this article helpful?

0 0

Post a comment