-
-
Notifications
You must be signed in to change notification settings - Fork 304
Create Python-Function-LEN.md #1030
Changes from 1 commit
9b47fb0
21d79fe
98a663b
b9aab7a
2ed88ab
fa646bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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` - 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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
## Return Value | ||
|
||
This function returns the number of elements in the list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But you just mentioned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alayek There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in Python, everything is an object. It's too broad. For instance, what would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its according to the official documentation and that is why I have mentioned that "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)" |
||
|
||
## Code Sample | ||
|
||
```python | ||
list1 = [123, 'xyz', 'zara'] | ||
str1 = 'basketball' | ||
print(len(list1)) # prints 3 | ||
print(len(str1)) # prints 10 | ||
``` | ||
|
||
:rocket: [Run Code](https://repl.it/CUmt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add more example with tuple and dictionaries. Also add comments as to why which value would be printed. |
||
|
||
[Official Docs](https://docs.python.org/3/library/functions.html#len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by length of an
object
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
built in functionbuilt-in functionargumentargument,x
.x
.