Python 的 字符串结尾

等级 134 次按键

这检查字符串是否以后缀结尾。endswith()方法返回True或False。

Python 代码

# endswith()在字符串以指定后缀结尾时返回True,否则返回False
# "file.txt"以".txt"结尾,所以打印True
1print("file.txt".endswith(".txt"))

运行结果

True
用这段代码练习打字

可以用这段代码练习打字。成绩不会计入排行榜。

这段代码中的符号

这段 Python 代码中需要输入的符号及其出现次数。

  • "× 4
  • .× 3
  • (× 2
  • )× 2

Python 等级 1 的更多代码示例

← 返回 Python 打字练习