Page 184 - Ai_V3.0_c11_flipbook
P. 184
# List variable
numbers = [1, 2, 3, 4, 5]
# Tuple variable
point = (10, 20)
# Dictionary variable
person = {'name': 'Yash', 'age': 30}
Multiple Assignment
Multiple assignment of variables, also known as parallel assignment, is a powerful feature in many programming
languages that allows you to assign multiple variables at once. This concept can significantly enhance code readability,
efficiency, and flexibility.
For example:
x, y, z = 1, 2, 3
In given code, the values 1, 2, and 3 are assigned to variables x, y, and z, respectively. This simultaneous assignment
saves lines of code and improves readability compared to assigning each variable separately.
Multiple assignment is not limited to simple variables. It works with any iterable data structure, including tuples, lists,
and even custom objects that support iteration and unpacking.
For example:
point = (5, 10)
x, y = point
In the given code, the values (5, 10) are unpacked from the point tuple and assigned to variables x and y respectively.
This syntax is concise and expressive, making code more elegant and maintainable.
For example:
[a, b, c] = [1, 2, 3]
In this example, a, b, and c are assigned the values 1, 2, and 3 respectively from the list [1, 2, 3].
Data Types in Python
Data types in Python specify the type of values that a variable can hold. Python is dynamically typed, which means there
is no need to declare the data type of a variable explicitly. Python automatically assigns the appropriate data type to a
variable based on the value assigned to it.
This flexibility makes Python a versatile language for various programming tasks. Python allows different operations to
be performed on different data types.
The following tree structure shows the various data types used in Python:
Data Types
Numeric Dictionary Sequence Set Boolean None
Floating
Integer Complex List Tuple String
Point
182 Touchpad Artificial Intelligence (Ver. 3.0)-XI

