Page 185 - Ai_V3.0_c11_flipbook
P. 185
Numeric Data Type
Numeric data types are used to store numeric values. In Python, there are three main numeric data types: integer,
floating point, and complex.
• • 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
• • 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
• • 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.
• • 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']
• • 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')
• • 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.
Python Programming 183

