下面是Python的代码:

string = "hello world"
new_string = string[:-1]
print(new_string)

输出结果为:

hello worl

解释:

  • string是原始字符串。
  • new_string是去掉最后一位字母后的新字符串。
  • string[:-1]表示取string的第一个字符到倒数第二个字符组成的子字符串。
string字符串去掉最后一位字母

原文地址: https://www.cveoy.top/t/topic/ggLy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录