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

Article for Python 3 built-in function (len) #1029

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Challenge-Logical-Order-In-If-Else-Statements.md
Original file line number Diff line number Diff line change
@@ -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.


24 changes: 24 additions & 0 deletions Python-Function-LEN.md
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).

## 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)