Python‎ > ‎Built-in‎ > ‎

len()

http://www.adilwaseem.com/

Defintion
Return the number of items of a sequence or collection.

Syntax
len(x)

Parameters
x=item

Examples
The method return the length of string.
 >>> 
>>> b="Python Lake"
>>> len(b)
11

The method return with: 
 >>> 
>>> x="Python Lake is wonderful sources of learning"
>>> len(x)
44
>>> 

len(str)
The method return with the length of the string.
 >>> 
>>> a="python Lake"
>>> len(a)
11

len(set)
 >>> set1={4,5,6,7}
>>> len(set1)
4
>>>

len(set)
The return is:
 >>>import operator
>>> x={2,5,6,7,8,8}
5
>>> x={2,5,6,7,8}
5
>>> len(x)
5

__len__
The test return the length of set equal to len(set)
 >>> set1={4,5,6,7}
>>> set1.__len__()
4

operator.is_not
Testing the string through built in method operator.is_not().
 >>> len("Python Lake") is not len("Python Lake")
False

len(tuple())
Return with the length of the tuple.
 tuple1=(44,22,13,22,45,555,32,33)
y=len(tuple1)
print(" number of items in tuple1 are: ", y)

len(str.partition())
The method return with length of partition string.
 >>> len("Python Lake".partition("Lake"))
3

len(divmod())
The methods finds the length of value of x after divmod().
 x=divmod(5,3)
>>> x
(1, 2)
>>> len(x)
2

len(operator.length_hint(list))
The method returns with the length of interable.
 >>>import operator
>>> x=[101,102,103,104,105]
>>> operator.length_hint(x)
5
>>> len(x)
5

len(str.rjust())
The returns are :
 >>> type("Python".rjust(10))
<class 'str'>
>>> "Python".rjust(10).__eq__('    Python')
True
>>> len('    Python')
10
>>> len("Python".rjust(10))
10
>>> 


The syntax open the input() into new default browser.
import webbrowser

x=input("Please enter your web address: ")

y=len(x)
z=float(y)

if z > 7:
    webbrowser.open_new_tab(x)
else:
    
>>> 
Please enter your web address: cnn.com
>>>

Comments