Page 186 - AI Ver 3.0 Class 11
P. 186
For example:
multiline_string = """
This is a multiline string.
It can span across multiple lines.
Triple quotes allow you to include line breaks without using escape characters.
"""
Set Data Type
In Python, a set is an unordered collection of unique elements. Sets are mutable, meaning you can add or remove
elements from them after they are created. You can create a set in Python by enclosing a comma-separated list of
elements within curly braces {}. The key characteristic of sets in Python is that they do not allow duplicate elements.
For example:
# Creating a set using curly braces
my_set = {1, 2, 3, 4, 5}
Boolean Data Type
The Boolean data type in Python represents one of two values: True or False. Booleans are commonly used for logical
operations, conditional expressions, and control flow in programming. In Python, the integer value 0 is considered false,
while any non-zero integer value is considered true. This means that when evaluated in a boolean context, 0 evaluates
to False, and any other non-zero integer value evaluates to True.
For example:
is_valid = True
is_empty = False
None Data Type
None is a special constant in Python that represents the absence of a value or represents a null value. It is often used to
indicate that a variable has not been assigned a value.
For example:
x = None
Type Casting
Type casting, also known as type conversion, in Python refers to the process of converting a variable from one data
type to another. Python has two types of type casting: implicit and explicit. In the case of implicit type casting, Python
automatically converts one data type to another data type. On the other hand, we need to convert one data type to
another data type explicitly by using the Python functions. Python provides several built-in functions for type casting.
Some of them are as follows:
• • int(): Converts a value to an integer.
• • float(): Converts a value to a float.
• • str(): Converts a value to a string.
• • bool(): Converts a value to a boolean.
• • list(): Converts a value to a list.
• • tuple(): Converts a value to a tuple.
• • set(): Converts a value to a set.
• • dict(): Converts a sequence of key-value pairs to a dictionary.
Program 12: To demonstrate the concept of type casting
# Demonstrating type casting in Python
# Initial values of different types
184 Touchpad Artificial Intelligence (Ver. 3.0)-XI

