什么是函数

引言

现在有这么个情况:假设我们python中的len方法不可以使用了,而恰好你又要计算一个字符串的长度你该怎么办呢?有人说:‘简单,可以使用for循环嘛

s1 = "hello world"
length = 0
for i in s1:
    length = length+1

print(length)
使用for循环计算

相关文章:

猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2021-11-12
  • 2021-05-14
相关资源
相似解决方案