Python:反转字符串

标签 python list reverse

<分区>

Possible Duplicate:
Reverse a string in Python

我明白 Python 中的数据(字符串)是像列表一样存储的

例子:

string1 = "foo"
"foo"[1] = "o"

如何使用 list.reverse 函数反转字符串中的字符?这样我输入“foo”并返回“oof”

最佳答案

你通常不会。

>>> "foo"[::-1]
'oof'

关于Python:反转字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557950/

相关文章:

python - 用于运行特定单元格的 Jupyter 键盘快捷键

python - 通过迭代列表追加项目

python - 这段代码究竟是如何在 Python 中反转字符串的

python - 给定一个整数列表和一个索引列表,我如何使用 map 将 10 添加到第一个列表中的特定元素?

Django 反向查找链接查询集

c - 我需要帮助理解反转字符串的代码

python - 自动格式化python代码的工具?

python - GridFS.put() 和 GridFSBucket.upload_from_stream() 的区别

python - 通过模式匹配相乘

python - 方法列表