fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,31 @@
---
title: String Methods
---
**TODO: `string` basic info**
[Python Docs - Strings](https://docs.python.org/3/library/stdtypes.html#strings)
**Creation:**
An empty `string` is created using a pair of quotation marks or apostrophes:
```shell
>>> new_string = ''
>>> type(new_string)
<class 'string'>
>>> len(new_string)
0
```
[Python Docs - More on Strings](https://docs.python.org/3/tutorial/datastructures.html#more-on-strings)
* `string.find('you')` Returns the lowest position that the substring is found at.
* `str.join(iterable)` Join all elements in an `iterable` with a specified string.
* `str.replace(old, new, max)` method is used to replace the substring `old` with the string `new` for a total of `max` times. This method returns a new copy of the string with the replacement, and the original `str` is unchanged.
* `string.split(separator, maxsplit)` Returns a list of substrings delimited by the `separator`, an optional `maxsplit` number of times, and if not specified, the string will be split on all instances of the `separator`.
* `string.strip(to_strip)` Returns a string with `to_strip` removed from both the beginning and the end of the string. If `to_strip` is not specified, this will strip all whitespace characters.

View File

@ -0,0 +1,31 @@
---
title: String Find Method
---
## String Find Method
There are two options for finding a substring within a string in Python, `find()` and `rfind()`.
Each will return the position that the substring is found at. The difference between the two is that `find()` returns the lowest position, and `rfind()` returns the highest position.
Optional start and end arguments can be provided to limit the search for the substring to within portions of the string.
Example:
```shell
>>> string = "Don't you call me a mindless philosopher, you overweight glob of grease!"
>>> string.find('you')
6
>>> string.rfind('you')
42
```
If the substring is not found, -1 is returned.
```shell
>>> string = "Don't you call me a mindless philosopher, you overweight glob of grease!"
>>> string.find('you', 43) # find 'you' in string anywhere from position 43 to the end of the string
-1
```
More Information:
String methods <a href='https://docs.python.org/3/library/stdtypes.html#string-methods' target='_blank' rel='nofollow'>documentation</a>.

View File

@ -0,0 +1,60 @@
---
title: String Join Method
---
## String Join Method
The `str.join(iterable)` method is used to join all elements in an `iterable` with a specified string ```str```.
If the iterable contains any non-string values, it raises a TypeError exception.
`iterable`: All iterables of string. Could a list of strings, tuple of string or even a plain string.
#### Examples
1) Join a ist of strings with `":"`
```python
print ":".join(["freeCodeCamp", "is", "fun"])
```
Output
```shell
freeCodeCamp:is:fun
```
2) Join a tuple of strings with `" and "`
```python
print " and ".join(["A", "B", "C"])
```
Output
```shell
A and B and C
```
3) Insert a `" "` after every character in a string
```python
print " ".join("freeCodeCamp")
```
Output:
```shell
f r e e C o d e C a m p
```
4) Joining with empty string.
```python
list1 = ['p','r','o','g','r','a','m']
print("".join(list1))
```
Output:
```shell
program
```
5) Joining with sets.
```python
test = {'2', '1', '3'}
s = ', '
print(s.join(test))
```
Output:
```shell
2, 3, 1
```
#### More Information:
<a href='https://docs.python.org/2/library/stdtypes.html#str.join' target='_blank' rel='nofollow'>Python Documentation on String Join</a>

View File

@ -0,0 +1,38 @@
---
title: String Replace Method
---
## String Replace Method
The `str.replace(old, new, max)` method is used to replace the substring `old` with the string `new` for a total of `max` times. This method returns a new copy of the string with the replacement. The original string `str` is unchanged.
#### Examples
1. Replace all occurrences of `"is"` with `"WAS"`
```python
string = "This is nice. This is good."
newString = string.replace("is","WAS")
print(newString)
```
Output
```python
ThWAS WAS nice. ThWAS WAS good.
```
2. Replace the first 2 occurrences of `"is"` with `"WAS"`
```python
string = "This is nice. This is good."
newString = string.replace("is","WAS", 2)
print(newString)
```
Output
```python
ThWAS WAS nice. This is good.
```
#### More Information:
Read more about string replacement in the <a href='https://docs.python.org/2/library/string.html#string.replace' target='_blank' rel='nofollow'>Python docs</a>

View File

@ -0,0 +1,71 @@
---
title: String Split Method
---
The `split()` function is commonly used for string splitting in Python.
#### The `split()` method
Template: `string.split(separator, maxsplit)`
`separator`: The delimiter string. You split the string based on this character. For eg. it could be " ", ":", ";" etc
`maxsplit`: The number of times to split the string based on the `separator`. If not specified or -1, the string is split based on all occurrences of the `separator`
This method returns a list of substrings delimited by the `separator`
#### Examples
1) Split string on space: " "
```python
string = "freeCodeCamp is fun."
print(string.split(" "))
```
Output:
```python
['freeCodeCamp', 'is', 'fun.']
```
2) Split string on comma: ","
```python
string = "freeCodeCamp,is fun, and informative"
print(string.split(","))
```
Output:
```python
['freeCodeCamp', 'is fun', ' and informative']
```
3) No `separator` specified
```python
string = "freeCodeCamp is fun and informative"
print(string.split())
```
Output:
```python
['freeCodeCamp', 'is', 'fun', 'and', 'informative']
```
Note: If no `separator` is specified, then the string is stripped of __all__ whitespace
```python
string = "freeCodeCamp is fun and informative"
print(string.split())
```
Output:
```python
['freeCodeCamp', 'is', 'fun', 'and', 'informative']
```
3) Split string using `maxsplit`. Here we split the string on " " twice:
```python
string = "freeCodeCamp is fun and informative"
print(string.split(" ", 2))
```
Output:
```python
['freeCodeCamp', 'is', 'fun and informative']
```
#### More Information
Check out the <a href='https://docs.python.org/2/library/stdtypes.html#str.split' target='_blank' rel='nofollow'>Python docs on string splitting</a>

View File

@ -0,0 +1,37 @@
---
title: String Strip Method
---
## String Strip Method
There are three options for stripping characters from a string in Python, `lstrip()`, `rstrip()` and `strip()`.
Each will return a copy of the string with characters removed, at from the beginning, the end or both beginning and end. If no arguments are given the default is to strip whitespace characters.
Example:
```py
>>> string = ' Hello, World! '
>>> strip_beginning = string.lstrip()
>>> strip_beginning
'Hello, World! '
>>> strip_end = string.rstrip()
>>> strip_end
' Hello, World!'
>>> strip_both = string.strip()
>>> strip_both
'Hello, World!'
```
An optional argument can be provided as a string containing all characters you wish to strip.
```py
>>> url = 'www.example.com/'
>>> url.strip('w./')
'example.com'
```
However, do notice that only the first `.` got stripped from the string. This is because the `strip` function only strips the argument characters that lie at the left or rightmost. Since w comes before the first `.` they get stripped together, whereas 'com' is present in the right end before the `.` after stripping `/`
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
String methods <a href='https://docs.python.org/3/library/stdtypes.html#string-methods' target='_blank' rel='nofollow'>documentation</a>.