Get The Most Affordable Hosting in the World!
Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.
Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!
Get Started Now!In Python, array is a homogenous collection of Python's built in data types such as strings, integer or float objects. However, array itself is not a built-in type, instead we need to use the array class in Python's built-in array module.
First Method
To join two arrays, we can do it by appending each item from one array to other.
Here are two Python arrays −
Run a for loop on the array "b". Fetch each number from "b" and append it to array "a" with the following loop statement −
The array "a" now contains elements from "a" as well as "b".
Here is the complete code −
It will produce the following output −
array('i', [10, 5, 15, 4, 6, 20, 9, 2, 7, 8, 11, 3, 10])
Second Method
Using another method to join two arrays, first convert arrays to list objects −
The list objects can be concatenated with the '+' operator.
If "z" list is converted back to array, you get an array that represents the joined arrays −
Here is the complete code −
Third Method
We can also use the extend() method from the List class to append elements from one list to another.
First, convert the array to a list and then call the extend() method to merge the two lists −
It will produce the following output −
array('i', [10, 5, 15, 4, 6, 20, 9, 2, 7, 8, 11, 3, 10])
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.