Description
The Python len () method returns the length of an object (character, list, tuple, and so on) or the number of items.
Grammar
Len () method syntax:
Len (s)
return value
Returns the length of the object.
Instance
The following examples show how Len () is used:
>>>str = "Runoob" >>> len (str) # string length 6>>> L = [1,2,3,4,5]>>> len (l) # Number of list elements 5
Len is called when it calls Len (instance). Len is a built-in function that can return the length of an object. It can be used for any object that is supposed to have a length.
The Len of the string is the number of its characters, and the Len of the dictionary is the number of its keywords, and the Len of the list or sequence is the number of elements. For class instances, define the Len method, and then self-edit ...
In SQLite3, to query the number of results of a SELECT statement, you cannot directly use the Len (RES) statement, you need to assign the cursor's Fetchall method to an array, and then use the Len method for the data, as follows:
Import sqlite3 conn = sqlite.connect (' test.db ') cursor = conn.cursor () cursor.execute ("Select UID, Username, userpwd from member ") records = Cursor.fetchall () num = Len (records)
"Recommended"
1. Learn more about the special function __len__ (self) in Python
2. Summarize the use instances of the Len () function in Python
3. Example Tutorials for using Python-specific class methods
4. Python Magic method __getitem__, __setitem__, __delitem__, __len__ respectively introduced