Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
28 views

Introduction Python Lenguage

Introduccion al lenguaje de python en ingles
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Introduction Python Lenguage

Introduccion al lenguaje de python en ingles
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LISTS, ARRAYS, AND MATRIX

SUMMARY
by: Hernando Lora Guzmán.

Bibliographical source:

https://elibro-net.lproxy.tecnologicocomfenalco.edu.co/es/lc/tecnologicocomfenalco/titulos/106404

Introduction:
In Python, lists, arrays, and matrix are fundamental data structures that enable the
organization and manipulation of sets of elements. Each has its own characteristics and is
used in different contexts based on program requirements.

Lists:
A list is a data structure that allows storing and organizing a collection of elements. Some
key features of lists in Python include:
Ordered Collection: Elements in a list are ordered and can be accessed using indices.
Mutability: Lists are mutable, meaning you can modify, add, or remove elements after
creating the list.
Various Data Types: You can store elements of different types in a single list, such as
integers, strings, booleans, or other lists.
Syntax: They are defined using square brackets [], and elements are separated by
commas.
Example:

Indexes and Slicing:


You can access individual elements using indices. Indices start from 0.
Slicing can be performed to obtain subsets of the list.
Methods and Operations:
Lists have built-in methods for various operations, such as adding elements (append()),
inserting elements at a specific position (insert()), removing elements (remove()), counting
occurrences (count()), reversing the list (reverse()), and sorting the list (sort()), among
others.

Lists are a versatile and widely used tool in Python for efficiently handling collections of
data. Their ability to contain elements of different types and be modified after creation
makes them suitable for a variety of tasks in programming.4

Arrays:
an array is a data structure that provides a way to store elements of the same type
efficiently in terms of space and time. Although lists can also contain elements of different
types, arrays are designed to hold homogeneous elements. To work with arrays in Python,
the array module is typically used, which provides a homogeneous data type called array.
Key features of arrays in Python:
Homogeneity: All elements in an array must be of the same data type, such as integers,
floating-point numbers, characters, etc.
Efficiency: Arrays are more efficient in terms of space and time compared to lists,
especially when it comes to numerical operations.
Syntax: They are used through the array module, which needs to be imported.
They are created by specifying the data type of the elements and providing a sequence of
values of the same type.
Indexes and Operations:
Like lists, elements in an array are accessible using indices.
Arrays support efficient operations such as array addition, scalar multiplication, etc.

Methods:
Arrays have useful methods such as append() to add elements to the end of the array,
insert() to insert elements at a specific position, and others.

Matrix:
a matrix is not a native data type, but you can represent it using nested lists or by using
specialized libraries like NumPy. In general terms, a matrix is a two-dimensional data
structure that contains elements organized in rows and columns. Each element in the
matrix can be referenced by a pair of indices indicating its position in the row and column.

Here are two common ways to represent matrices in Python:

1. Nested Lists:
You can represent a matrix using nested lists, where each inner list represents a row of
the matrix. The resulting matrix is essentially a list of lists.
2. NumPy:
NumPy is a powerful library in Python for working with matrices and numerical operations.
It provides a data type called numpy.ndarray that is more efficient for handling numerical
data and performing matrix operations.

With NumPy, you gain significant advantages in terms of efficiency and facilities for matrix
operations, but you need to install the library if you haven't already (pip install numpy).

Conclusion:
In summary, lists provide flexibility and versatility for working with collections of elements
of different types. Arrays offer efficiency in numeric operations by requiring homogeneous
data types. Matrices, while not native, can be represented using nested lists or specialized
libraries like NumPy for advanced manipulation of numeric data. The choice among these
structures depends on the specific requirements of your program, balancing flexibility with
performance.

You might also like