官术网_书友最值得收藏!

Arrays

An array (or list in some scripting languages) is used to store a similar set of multiple values inside a single variable. This helps to ensure all data types with similar meanings are stored in a single variable, and also we can easily loop through these array objects to fetch the values stored in an array.

Consider the following example:

countries=["India","China","USA","UK"]
for specific country in countries
Perform action

As we can see in the variable declaration, now we are declaring a similar data type with a similar context or meaning by grouping them together and assigning them into a single variable. In our example, it's the country names all assigned to an array variable named countries. In the next line, we are now iterating using the loop method, and for every specific country in the list or array of countries, we will perform the action. In this case, the loop will be executed to perform the action for each country, from the country name India to the end of the country name UK.

Each value stored in an array is referred to as an element of the array. Additionally, an array can be easily sorted, which means irrespective of the order of the elements in the array, we can get a sorted list or array by calling some additional programming tasks.

Let's consider an example:

countries=["India", "China", "USA","UK"]
Sort (countries)

The result will be as follows:

countries=["China","India","UK",USA"]

The sort functionality ensured that all the elements inside the array are sorted alphabetically and stored in the sorted order.

主站蜘蛛池模板: 上饶市| 龙游县| 十堰市| 岚皋县| 绥宁县| 黔西县| 黄石市| 兴仁县| 武夷山市| 潜山县| 巴彦淖尔市| 金华市| 巴中市| 清涧县| 台东市| 黄骅市| 穆棱市| 米泉市| 安化县| 精河县| 香河县| 开鲁县| 乌拉特中旗| 苗栗市| 连平县| 萝北县| 东莞市| 新竹市| 正镶白旗| 仁化县| 沙坪坝区| 鹿泉市| 阿拉善左旗| 合水县| 禹州市| 申扎县| 乌海市| 富民县| 迁安市| 高淳县| 贵港市|