array Python module
| ast Python module
| code Python module
| COM PHP module
| Ev PHP module
| imp Python module
| io Python module
| math Python module
| os Python module
| Python functions
| Rar PHP module
| re Python module
| resource Python module
| time Python module
| UI PHP module
👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
Use the .length syntax of add at the end of an array name to access the value of the length property.
Here is where the length property can come in handy. Let’s say we have a list of books that we sell that appeared in the New York Times bestselling fiction of 2019. we can find out how many books we are selling are in this list using the length property:
When we run our code, the program returns: 6.
we first declare a constant, called nyt_fiction_best_sellers_2019 that stores constant a list of books in our inventory appeared in. the New York Times fiction Best Sellers of 2019 list. Next, we use the length property erty to find out the length of this list. In this case, there are six values ‚Äã‚Äãin our list, so the length property declarations: 6.
Suppose we want to find the average age of members in a dance class. We have a list which stores the dancers ages. Next, we decide that we want to round off the nearest whole mean. We would need to use the length property to retrieve the number of items in the list. This value will help us calculate an average
Here is an example program that would allow us to calculate the average age of members of the dance class.
Our code returns:
< p? > First , we set the value of sum
to 0 because we need to declare a variable before it can be used. Next, we add each dancer’s age to sum
in our for
After running the for loop, our program calculates the average age of the class members by dividing sum (the sum of the ages of all the dancers) for dancer_ages.length (the number of people in the class of dance). Next, we use the Math.round () method to round our value to the nearest integer
👻 Read also: what is the best laptop for engineering students?
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
Paris | 2023-04-01
San Francisco | 2023-04-01
Singapore | 2023-04-01