From 9b47fb08b8a826a1aa87ace750d0ec59b49953a6 Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Wed, 25 May 2016 06:25:25 +0530 Subject: [PATCH 1/6] Create Python-Function-LEN.md --- Python-Function-LEN.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Python-Function-LEN.md diff --git a/Python-Function-LEN.md b/Python-Function-LEN.md new file mode 100644 index 000000000..6bcf2708d --- /dev/null +++ b/Python-Function-LEN.md @@ -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). + +## Return Value + +This function returns the number of elements in the list + +## 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) + +[Official Docs](https://docs.python.org/3/library/functions.html#len) From 21d79fe069d9f2d72705badd0d2074e4923009e6 Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Wed, 25 May 2016 13:04:09 +0530 Subject: [PATCH 2/6] Update Python-Function-LEN.md --- Python-Function-LEN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python-Function-LEN.md b/Python-Function-LEN.md index 6bcf2708d..7c57a2e41 100644 --- a/Python-Function-LEN.md +++ b/Python-Function-LEN.md @@ -8,7 +8,7 @@ It takes one argument `x` - argument may be a sequence (such as a string, bytes, ## Return Value -This function returns the number of elements in the list +This function returns the number of elements in the argument which is passed to the `len()` function. ## Code Sample From 98a663ba4cecc38ddb091e264372a9b43d9a277d Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Wed, 25 May 2016 13:11:05 +0530 Subject: [PATCH 3/6] Update Python-Function-LEN.md --- Python-Function-LEN.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Python-Function-LEN.md b/Python-Function-LEN.md index 7c57a2e41..c8baa201e 100644 --- a/Python-Function-LEN.md +++ b/Python-Function-LEN.md @@ -4,7 +4,7 @@ ## 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). +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 @@ -13,10 +13,17 @@ This function returns the number of elements in the argument which is passed to ## Code Sample ```python -list1 = [123, 'xyz', 'zara'] -str1 = 'basketball' -print(len(list1)) # prints 3 -print(len(str1)) # prints 10 +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) From b9aab7adb0c3a196058328e91f6346ca6fefb854 Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Wed, 25 May 2016 13:11:44 +0530 Subject: [PATCH 4/6] Update Python-Function-LEN.md --- Python-Function-LEN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python-Function-LEN.md b/Python-Function-LEN.md index c8baa201e..7622ff180 100644 --- a/Python-Function-LEN.md +++ b/Python-Function-LEN.md @@ -26,6 +26,6 @@ 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) +:rocket: [Run Code](https://repl.it/CUmt/15) [Official Docs](https://docs.python.org/3/library/functions.html#len) From 2ed88abcf9822a845a91a9e8e7573b9f884c288f Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Wed, 25 May 2016 13:12:59 +0530 Subject: [PATCH 5/6] Update Python-Function-LEN.md --- Python-Function-LEN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python-Function-LEN.md b/Python-Function-LEN.md index 7622ff180..97f93dc40 100644 --- a/Python-Function-LEN.md +++ b/Python-Function-LEN.md @@ -4,7 +4,7 @@ ## 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). +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 From fa646bf30936cfeeaf73a2a77d4612fc1f8ab2c8 Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Wed, 25 May 2016 13:55:15 +0530 Subject: [PATCH 6/6] Update Python-Function-LEN.md --- Python-Function-LEN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python-Function-LEN.md b/Python-Function-LEN.md index 97f93dc40..3a83a2c14 100644 --- a/Python-Function-LEN.md +++ b/Python-Function-LEN.md @@ -1,10 +1,10 @@ # 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`. +`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). +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