diff --git a/Challenge-Logical-Order-In-If-Else-Statements.md b/Challenge-Logical-Order-In-If-Else-Statements.md new file mode 100644 index 000000000..4c1ab378e --- /dev/null +++ b/Challenge-Logical-Order-In-If-Else-Statements.md @@ -0,0 +1,51 @@ +# Challenge Logical Order in If Else Statements + +Order is important in `if`, `else if` and `else` statements. + +The loop is executed from top to bottom so you will want to be careful of which statement comes first. + +Take these two functions as an example. + +## Examples: + +```javascript +function foo(x) { + if (x < 1) { + return "Less than one"; + } + else if (x < 2) { + return "Less than two"; + } + else { + return "Greater than or equal to two"; + } +} +``` + +And the second just switches the order of the statements: + +```javascript +function bar(x) { + if (x < 2) { + return "Less than two"; + } + else if (x < 1) { + return "Less than one"; + } + else { + return "Greater than or equal to two"; + } +} +``` + +While these two functions look nearly identical, if we pass a number to both we get different outputs. + +```javascript +foo(0) // "Less than one" + +bar(0) // "Less than two" +``` + +So be careful while using the `if`, `else if` and `else` statements and always remember that these are executed from top to bottom. Keep this in mind placing your statements accordingly so that you get the desired output. + + 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)