怎样在 Python 求一个字符串的长度?

2026-02-15 13:38:12

1、首先,右键点击【项目】,创建一个【Python】文件

怎样在 Python 求一个字符串的长度?

2、接着,在右侧输入代码,代码写在【下一步】

怎样在 Python 求一个字符串的长度?

3、然后,复制代码粘贴到文件中

if __name__ == '__main__':


   s = raw_input('please input a string:\n')
   print 'the string has %d characters.' % len(s)

怎样在 Python 求一个字符串的长度?

4、随后,右键选择运行代码文件

怎样在 Python 求一个字符串的长度?

5、最后,在最下面就可以看到运行结果了

怎样在 Python 求一个字符串的长度?

猜你喜欢