# String Methods

Python provides a set of built-in **string methods** that we can use to modify and manipulate strings. Here is a list of some of the most commonly used built-in string methods in Python:

`upper()`: The `upper()` method converts a string to uppercase.

Syntax:

```python
string.upper()
```

Example:

```python
name = "john"
print(name.upper()) 
 # Output: JOHN
```

`lower()`: The `lower()` method converts a string to lowercase.

Syntax:

```python
string.lower()
```

Example:

```python
name = "JANE"
print(name.lower())  
# Output: jane
```

`strip()`: The `strip()` method removes any white spaces before and after the string.

Syntax:

```python
string.strip()
```

Example:

```python
string_with_spaces = "  hello  "
print(string_with_spaces.strip())  
# Output: "hello"
```

`rstrip()`: The `rstrip()` method removes any trailing characters.

Syntax:

```python
string.rstrip()
```

Example:

```python
string_with_trailing_characters = "hello!!!"
print(string_with_trailing_characters.rstrip("!"))  
# Output: "hello"
```

`replace()`: The `replace()` method replaces all occurrences of a string with another string.

Syntax:

```python
string.replace(old_value, new_value)
```

Example:

```python
string_with_replacement = "hello world"
print(string_with_replacement.replace("world", "universe"))  
# Output: "hello universe"
```

`split()`: The `split()` method splits the given string at the specified instance and returns the separated strings as list items.

Syntax:

```python
string.split(separator)
```

Example:

```python
string_to_split = "apple,banana,orange"
print(string_to_split.split(","))  # Output: ["apple", "banana", "orange"]
```

`capitalize()`: The `capitalize()` method turns only the first character of the string to uppercase and the rest of the characters to lowercase.

Syntax:

```python
string.capitalize()
```

Example:

```python
name = "jane DOE"
print(name.capitalize())  # Output: "Jane doe"
```

`count()`: The `count()` method returns the number of times the given value has occurred within the given string.

Syntax:

```python
string.count(value)
```

Example:

```python
string_to_count = "apple,banana,orange,apple"
print(string_to_count.count("apple"))  
# Output: 2
```

`find()`: The `find()` method searches for the first occurrence of the given value and returns the index where it is present. If the given value is absent from the string, it returns -1.

Syntax:

```python
string.find(value)
```

Example:

```python
string_to_find = "hello world"
print(string_to_find.find("world"))  # Output: 6
```

`center()`: The `center()` method aligns the string to the center as per the parameters given by the user.

Syntax:

```python
string.center(length, character)
```

Example:

```python
string_to_center = "hello"
print(string_to_center.center(10, "-"))  
# Output: "--hello---"
```

`title()`: The `title()` method capitalizes each letter of the word within the string.

Syntax:

```python
string.title()
```

Example:

```python
string_to_title = "hello world"
print(string_to_title.title())  
# Output: "Hello World"
```

`swapcase()`: The `swapcase()` method changes the character casing of the string. Upper case characters are converted to lower case and lower case characters to upper case.

Syntax:

```python
string.swapcase()
```

And here is an example of how to use it in Python:

```python
original_string = "tHiS iS a StRiNg tO sWaPcAsE"
swapped_string = original_string.swapcase()

print("Original string: ", original_string)
print("Swapped string: ", swapped_string)
```

Output:

```python
Original string: tHiS iS a StRiNg tO sWaPcAsE
Swapped string: ThIs Is A sTrInG To SwApCaSe
```
