# Strings

Strings are sequences of characters. In Python, strings are Unicode by default, so they can represent text from many languages.

### Creating Strings

```python
single = 'Hello'
double = "Hello"
multi = """Hello,
world"""
```

### Indexing and Slicing

```python
text = "Python"

print(text[0])    # P
print(text[-1])   # n
print(text[1:4])  # yth
```

Slicing is `start` inclusive and `end` exclusive.

### Immutability

Strings are immutable, so you cannot change a character in place.

```python
text = "Hello"
# text[0] = "J"  # TypeError
```

### Common Operations

```python
greeting = "Hello" + " " + "World"
echo = "Hi" * 3
```

### Membership and Iteration

```python
if "World" in greeting:
    print("Found")

for ch in "Hi":
    print(ch)
```

### Formatting

Use f-strings for most cases:

```python
name = "Ada"
age = 28
print(f"{name} is {age} years old.")
```

`str.format()` is also common:

```python
print("{} {}".format("Hello", "World"))
```

### Useful Methods

```python
text = "  Hello World  "

print(text.lower())
print(text.upper())
print(text.strip())
print(text.replace("World", "Python"))
print(text.split())
```

[Next](https://kallyasmedia.gitbook.io/cit-python-cohort-three/week2/data-types/python_lists) | [Previous](https://kallyasmedia.gitbook.io/cit-python-cohort-three/week2/operators/bitwise)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kallyasmedia.gitbook.io/cit-python-cohort-three/week2/data-types/strings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
