# String Method

## What is a method?

A method is a function that is associated with a class.

This might not make sense, but basically it is a feature we can use to do something with a data type.

For example, we can use the `.split` method to split a string into pieces.

Here, the `.split` is a method to split a string data

## Lowercase and Uppercase methods

It is very important to know about these methods.

In English and a few other languages, the lowercase and uppercase is a very important difference.

To make sure we can handle these differences, we need to turn one into the other.

Usually, uppercase is turned to a lower case with the `lower()` method.

```py
print("HELLO".lower())
```

These kinds of method is usually used to handle inputs.

| Other uper/lower methods | Explanation |
| :-- | :-- |
| title() | To a title-format (Make every character in front of a word uppercase) |
| upper() | Transform into an uppercase |
| isupper() | Check if the string is uppercase |
| islower() | Check if the string is lowercase |

## `len()`

The `len()` method is used for checking how long a string is.

```py
print(len("Hello"))
```

`len` is the shortened word for 'length'.

## `index()`

The `index()` method will help you find where a 'substring' is located.

Substring is a part of a string, and the index is the position of the substring.

```py
print('abcdef'.index('abc')) # prints 0
```

If there is no substring, it will throw an error.

## Operators

Operators are used to perform mathematical operations.

In strings, they are used like a method shortcut.

<iframe
  loading="lazy"
  title="Python IDLE Trinket"
  src="https://trinket.io/embed/python/54f740c487"
  height="400"
/>

### `in`

This operator returns a Boolean of whether a substring exists in a string.

```py
print('abc' in 'abcdef') # prints True
```

### `+`

This operator is used to concatenate two strings.

```py
print('abc' + 'def') # prints abcdef
```

Concatenate means to combine together.

### `*`

This operator is used to repeat a string.

```py
print('abc' * 3) # prints abcabcabc
```

import Quiz from 'react-quiz-component';

<Quiz
  quiz={{
    quizTitle: 'Python Quiz 6',
    quizSynopsis: '문자열 메서드 연습',
    nrOfQuestions: '3',
    questions: [
      {
        question: 'len("Python")',
        questionType: 'text',
        answerSelectionType: 'single',
        answers: ['3', '4', '5', '6'],
        correctAnswer: '4',
        explanation:
          'len() is used tofind the length of the string. "Python" is 6 characters long.',
        point: '10',
      },
      {
        question: 'len("python"[0])',
        questionType: 'text',
        answerSelectionType: 'single',
        answers: ['1', '2', '0', '6'],
        correctAnswer: '1',
        explanation:
          'This was a trick question. [0] returns one character which is 1 length long.',
        point: '40',
      },
      {
        question: '"python"[1] * 3 + "python"[2] * 3 + "python"[3] * 3',
        questionType: 'text',
        answerSelectionType: 'single',
        answers: ['yyyttthhh', 'ttthhhyyy', 'hhhtttyyy', 'ttttttttt'],
        correctAnswer: '1',
        explanation: '[1] * 3 + [2] * 3 + [3] * 3 returns yyyttthhh',
        point: '50',
      },
    ],
  }}
/>
