【问题标题】:How to return the last character of a string in Python? [duplicate]如何在 Python 中返回字符串的最后一个字符? [复制]
【发布时间】:2021-11-22 17:24:33
【问题描述】:

我怎样才能得到这个字符串的最后一个字符?

seed_name = "Cocoa"

【问题讨论】:

标签: python


【解决方案1】:

official Python tutorial所示,

>>> word = 'Python'

[...]

索引也可以是负数,从右开始计数:

>>> word[-1]  # last character
'n'

【讨论】:

    猜你喜欢
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 2021-09-18
    • 2012-03-27
    • 1970-01-01
    • 2018-04-29
    相关资源
    最近更新 更多