在字符串中输出前100个字符

2024-04-25 05:41:49 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

来自python tutorial

Degenerate slice indices are handled gracefully: an index that is too large is replaced by the string size, an upper bound smaller than the lower bound returns an empty string.

所以使用x[:100]是安全的。

print my_string[0:100]

简单:

print mystring[:100]

相关问题 更多 >