Python has several basic numeric, string and Boolean types built into it. Objects of the Boolean data type may have one of two values: True or False. The most common (and simplest) example is a filter where all the records that meet a condition (true) are returned, like when using Excel and you filter for a specific value in a field. Watch the video to get an overview of the Boolean logic.
Share this step
Booleans
Python has several basic numeric, string and Boolean types built into it. Objects of the Boolean data type may have one of two values: True or False. The most common (and simplest) example is a filter where all the records that meet a condition (true) are returned, like when using Excel and you filter for a specific value in a field. Watch the video to get an overview of the Boolean logic.
Now, let’s look at how the Boolean logic takes form in Python.
For example:
Code:
is_true=Trueis_false=Falseprint(is_true,is_false)
Output:
True False
Boolean operators are combined with the and and or keywords.
For example:
Code:
is_trueandis_false
Output:
False
Code:
is_trueoris_false
Output:
True
Comparisons and other conditional expressions evaluate to either True or False.
For example:
Code:
1>2
Output:
False
Code:
2>1
Output:
True
Most objects in Python have a notion of True or False.
For example, empty sequences (list, dict, tuples) are treated as False if used in the control flow expressions. We can also see exactly what boolean value an object relates to by calling a method bool and passing that object parameter to this method.
For example:
Code:
bool([]),bool([1,2,3])
Output:
(False, True)
Code:
bool('Some String'),bool('')
Output:
(True, False)
Code:
bool(0),bool(1)
Output:
(False, True)
None
None is a Python’s null value type. Null value is used in various scenarios:
If a function doesn’t explicitly return a value, it implicitly returns the null value.
It is used in conditional expressions where we need to check if the object exists or not, or has a value or not.
For example:
Code:
a=Noneb=5aisNone
Output:
True
Code:
bisnotNone
Output:
True
It is also a common default value for optional functional arguments. Default values are assigned by Python to indicate that the function will take the default value if no value is passed during function call.
Datetime functionality is available in Python as a module. The built-in Python datetime provides date and time types.
Resources
If you want to stretch your boundaries and use the extended list of all the data types, check out the official Python documentation that provides all the information on the Python data model.