摘要:
一,循环和计数 下面这个程序计算了字母 a 在一个字符串中出现的次数: $ cat b.py #!/bin/python word = 'banana' count = 0 for letter in word: if letter == 'a': count = count + 1 print(c 阅读全文
摘要:
很多计算过程都需要每次从一个字符串中取一个字符。一般都是从头开始读取,依次得到每个字符,然后做些处理,一直到末尾。这种处理模式叫遍历。 1.使用while循环写一个遍历: $ cat a.py #!/bin/python fruit = 'banana' index = 0 while index 阅读全文