Skip to main content

ARRAYS VS VARIABLES IN PYTHON

Beginners mostly prefer variables over arrays, usually because they dont know the real power of array and they end up wasting time storing bunch of items in tens of variables whereas they can use an array and store all those into one variable


`


Why people use variables than array

Most programmers when starting out learn how to create variables to store information in as a way to make their program more dynamic. However, when they start writing a program, they soon find themselves using lots of variables for the same datatype which results in a waste of time and memory, then they say to themselves, “There has to be a better way.” If they are smart enough and love to research and update their programming, they will turn to using arrays. Arrays are a complex data structure compared to variables but once the progammer gets the hang of it he will be using it all the time for storing same datatype items. (btw in this blog post: https://cyber1571.blogspot.com/2022/10/arrays-in-python.html I have explained arrays in detail and you can learn it right away)

Difference between arrays and variables

These are two data types used for storing data in programs. Variables are containers used for storing a single data item in a program. Arrays are containers used for storing multiple data items in a program. An array can store many items of the same data type in one single array variable. For example, you can store a list of names in an array. Each name is a separate item.

 A variable is a named location in the computer’s memory used to store data. A variable can hold a value of a specific data type and An array too can hold a multiple values of a specific data type. A variable  and an array name can be almost any meaningful name.  

Preferring variables over array

There are, however, some reasons why you should use variables rather than arrays. If you have a relatively small amount of data that needs to be stored in the program, then using an array would only be a waste of time. You may be better off using a variable, even though the data could easily be stored in an array. The choice between using a variable or an array, however, is primarily a matter of how the data will be used in the program.

Power of array over variables

Variables are great for storing one data item, but arrays are better for storing a group of items. When you work with variables, you must use their names as pointers to the data items they contain. This can result in a lot of typing and make things more complicated. When you work with arrays, you can access each item by simply referring to its position in the array. This makes the overall process much smoother and easier to handle. In conclusion, arrays have more advantages than variables; however, variables are more appropriate when working with a small amount of data. When you are just starting out, you may want to use variables more often than arrays; however, as you gain more experience, you will get on to using arrays regularly.

Comments

Popular posts from this blog

HOW HAS THE CREATION OF CODE IMPACTED US AS HUMANS

The invention of coding has revolutionized the way we live and communicate. today almost everything around us is being run by a written code and thus has made our lives easier. look at the device you are reading this, the mobile phone where you get a notification, your washing machine, everything has a code that makes it function.  Coding, or programming, has had a significant impact on society and the way we live our lives. It has enabled the development of many technologies and tools that we use daily, such as computers, smartphones, and the internet. It has also brought in the idea of automation of processes leading to AI, and this has increased productivity and efficiency. It has hence contributed to the creation of new industries and job opportunities. interesting fields such as the internet of things, artificial intelligence, virtual reality, and 3d game development are created due to the advent of code. The Internet which came into existence due to coding has given humans li...

ARRAYS IN PYTHON

An array in python is a data structure that can hold more than one value at a time just like a list but their is a slight different in both of them which is discussed below. arrays can hold values of only single data type e.g integers or strings. All values in an array are indexed hence have their own unique address by which they can be called at any time. Now the indexing of array values in python always starts from 0, so if I have an array starting from 1 till 100 the first value of this array i.e 1 will have its index number as 0 and the array's last value i.e 100 will have an index number of 99. to visualise it we can say: array:     1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,9 , .........., 100           array's       index  :  0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , .........,  99 So now you can easily see how arrays are indexed in python so If using python code which is (discussed below), call out a specific index number it wi...