![]() ![]() You will see this output There are 5 squares in the list. Print(country, "has", len(country), "letters.") Print("There are", len(squares), "squares in the list.") The function can also be used to find the number of symbols in a string. ![]() The function len() returns the number of elements of the list you pass as argument. As an example, the code print(letters) would not work. If you try to use an index not between \(0\) to \(n-1\), you will get an execution error. You get an element of a list by writing the name of the list followed by the index of the element between square brackets. The element in a list with \(n\) elements, are numbered with indices from \(0\) to \(n-1\). You can make a shorter list in Python by writing the list elements separated by a comma between square brackets.
0 Comments
Leave a Reply. |