Page 67 - Touhpad Ai
P. 67
u Integer (int): Integers are whole numbers, positive or negative, without any decimal point. They can be of unlimited
size, subject only to the memory available.
For example:
x = 10
y = -20
u Floating Point (float): Floating-point numbers (floats) represent real numbers and are written with a decimal point
dividing the integer and fractional parts.
For example:
pi = 3.14
temperature = 98.6
u Complex (complex): Complex numbers are written with a “j” as the imaginary part. A complex number is of the form
x + yj and comprises a pair of floating point numbers. The first part (x) is called the real part, and the second one (y)
is called the imaginary part.
For example:
z = 5 + 3j
Dictionary Data Type
Dictionaries are unordered collections of key-value pairs enclosed in curly braces {}. Each key in a dictionary must be
unique and immutable, and it is used to access its corresponding value. Dictionaries are commonly used because they
provide fast access to values based on their keys.
For example:
person = {'name': 'John', 'age': 30, 'city': 'New York'}
Sequence Data Type
In Python, a sequence data type refers to an ordered collection of elements, where each element is indexed by a
non-negative integer. There are mainly three sequence data types in Python, including lists, tuples, and strings.
u Lists: Lists are mutable sequences, meaning their elements can be changed after creation. They are defined using
square brackets [ ] and can contain elements of different data types.
For example:
my_list = [1, 2, 3, 'a', 'b', 'c']
u Tuples: Tuples are immutable sequences, meaning their elements cannot be changed after creation. They are defined
using parentheses ( ) and can contain elements of different data types.
For example:
my_tuple = (1, 2, 3, 'a', 'b', 'c')
u Strings: Strings are immutable sequences of characters. They are defined using either single quotes (' ') or double
quotes (" ").
For example:
my_string = 'Hello, World!'
my_string1 = "Hello, World!"
In Python, you can create multiline strings using triple quotes. Triple quotes can be either single quotes (''') or double
quotes ("""). Multiline strings are often used for docstrings (documentation strings), multiline comments, or for storing
large blocks of text.
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.
"""
Basic Concepts of Artificial Intelligence 65

