Skip to content
This repository has been archived by the owner on Apr 1, 2021. It is now read-only.

Commit

Permalink
Create Python-Function-LEN.md (#1030)
Browse files Browse the repository at this point in the history
* Create Python-Function-LEN.md

* Update Python-Function-LEN.md

* Update Python-Function-LEN.md

* Update Python-Function-LEN.md

* Update Python-Function-LEN.md

* Update Python-Function-LEN.md
  • Loading branch information
varunu28 authored and Jonathan committed May 25, 2016
1 parent 68910bd commit 5306fa7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Python-Function-LEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Python len(x)

`len()` is a built-in function in Python 3. This method returns the length (the number of items) of an object. It takes one argument `x`.

## Arguments

It takes one argument, `x`. This argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

## Return Value

This function returns the number of elements in the argument which is passed to the `len()` function.

## Code Sample

```python
list1 = [123, 'xyz', 'zara'] # list
print(len(list1)) # prints 3 as there are 3 elements in the list1

str1 = 'basketball' # string
print(len(str1)) # prints 10 as the str1 is made of 10 characters

tuple1 = (2, 3, 4, 5) # tuple
print(len(tuple1)) # prints 4 as there are 4 elements in the tuple1

dict1 = {'name': 'John', 'age': 4, 'score': 45} # dictionary
print(len(dict1)) # prints 3 as there are 3 key and value pairs in the dict1
```

:rocket: [Run Code](https://repl.it/CUmt/15)

[Official Docs](https://docs.python.org/3/library/functions.html#len)

0 comments on commit 5306fa7

Please sign in to comment.