# list.reverse(), reversed()

Це приклади як застосовувати `reverse()`, `reversed()`.

Рядок перетворюється у список, далі -  `reverse()` або `reversed()`, потім - список перетворюється назад у рядок.

```python
#!/usr/bin/python3

strn = 'abcdefg'
temp_list = list(strn)            # ['a', 'b', 'c', 'd', 'e', 'f', 'g']

temp_list.reverse()               # ['g', 'f', 'e', 'd', 'c', 'b', 'a']
reverse_str = ''.join(temp_list)  # 'gfedcba'

print(reverse_str)



strn = 'abcdefg'
temp_list = list(strn)            # ['a', 'b', 'c', 'd', 'e', 'f', 'g']

temp_list = reversed(strn)        # <reversed object at 0x7fdc0cd68310>
temp_list = list(temp_list)       # ['g', 'f', 'e', 'd', 'c', 'b', 'a']
reverse_str = ''.join(temp_list)  # 'gfedcba'

print(reverse_str)

```

Це лише для демонстрації, як застосовувати ці метод і функцію. А взагалі реверс рядка простіше і швидше робити так:

```python
#!/usr/bin/python3

strn = 'abcdefg'
strn = strn[::-1]                 # 'gfedcba'
print(strn)

```


---

# 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://olexsyn.gitbook.io/enote/progr/python/list/list.reverse-reversed.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.
