Skip to main content

Python Arrays

Python Arrays


 Hi and welcome to this amazing tutorial on python. If you are new to this platform, please do check out our previous articles and subscribe to our YouTube channel to get the video tutorial of our tutorials.

In this tutorial, we will be discussing about python arrays. But Before getting started with python arrays, it is very important to note that python does not contain default input-data setting for its arrays but uses its python list which is found in the Numpy data import library

Generally, Python arrays are unique variables that can contain multiple values ​​at the same time. Arrays are the basic foundation in all data-science in python. 

To get the full package of python array, you need to install NumPy from the import library and then use the array () function to create an array and use it as an input list.

Let us now see how python array functions work as a list. Arrays are normally used to identify a particular object among a group of objects, which means we are just going to select an object from a set of objects.

 A python array begins with an opening square and end with a closing square bracket. Objects inside the square brackets are separated by commas.

How to access array element

An array element can be access by referring to the index number

Example

fruits= ["apple", "watermelon", "cherry"]
x = fruits[0]
print(x)

OUTPUT

Python Arrays

Finding the length of an array

We Use the len() to know the exact length of an array

colors = ["green", "violet", "red"]
x = len(colors)
print(x)

In this case, the len() function instructs the compiler to count the total number of objects within the square bracket

OUTPUT

Python Arrays

Looping array elements

Use the for in to through all the arrays elements

colors = ["green", "brown", "purple"]
for x in colors:
print(x)

As we earlier saw in array addition, the function for in in looping of arrays simply instructs the compiler to list the objects within the square bracket.

OUTPUT

Python Arrays

How to add array elements

Addition is done by using the append method

fruits = ["apple", "cherry", "watermelon"]
fruits.append("Honda")
print(fruits)

The compiler follows the instruction of the append function. Its adds what is in between the brackets of the append fuction.

OUTPUT

Python Arrays

How to remove arrays

colors = ["red", "blur", "violet"]
colors.remove("violet")
print(colors)

The compiler follows the instruction of the remove function that is it subtracts what is in the bracket of the remove function

OUTPUT

Python Arrays

In python, there are many default input list which can be used on arrays. These standards types are found in the NumPy package as python itself does support data input list.

Comments

Popular posts from this blog

Introduction to flask

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session because we are entering into one of python’s web-based application called flask. In this article, we are going to see the following What is flask Prequistes Installation of flask in python Some of flask template engine. What is flask? Flask is one of python-based framework which is used to create web applications. Flight is a very light web framework. During installation, flask comes with pre-installed modules and functions which are used to backup your own web applications. Flask is very easy to understand and perfect go-to for beginners and with flask, a web server can run in less than 3 lines of code. Prequistes Before learning flask, we recommend the reader to have a basic mastery of python concepts. Installation of flask  Before installing flask, we have to checked if python has been installed or. If n...

How to generate random numbers using NumP1

Hello. Welcome to another edition on this platform. For more better understanding, do checkout our YouTube channel to get the video tutorial. In this article of today, we are going to see how to generate random numbers using any of the following methods: Generating a random number Generating a random float and integer Generating random number arrays Generating random number from an array What is a random number? This is a number which cannot be predicted before its occurrence. This number might not different every time. Programmatically, they are two categories of random numbers:     Pseudo-Random numbers       True Random numbers. Just as programs which are written by programmers are a set of instructions, we must follow an algorithm to generate random numbers. Random numbers which are generated using an algorithm are called Pseudo-Random numbers. To generate a true random number, it is important to get the data from sources such as the keyboards, mou...

Introduction to Django

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session. we are entering into one of python’s application called Django. In this article, we are going to discuss the following: What is Django Why must we use Django  A brief history of Django Installation of Django Popularity of Django What is Django? Python has so many framework application and Django happen to be one of them. Being a python-based-framework, it is used to quickly create web applications.  When building websites, django provides similar ready-made components to handle user authentication, forms, a way to upload components. Why use django? Django is very fast. It takes applications from concept to applications very quickly Django has thousand available packages in it when it is installed. With django, we can launch web applications is a matter of hours. Django is a highly is secured and helps...