python学习笔记

1、字符串表示:‘’abc‘’ 或 ‘abc’ 或 str("abc")

2、取值-从0开始   str = "string"  str[0] --> 's'

3、截取-从1开始计数 str[a,b]---取第a+1个到第b个字符 即“前开后闭” (a,b]   ---截取不会改变原字符串

    例如 str[1,5]---->"trin"

    

4、for循环可以遍历任何序列的项目,如一个列表或者一个字符串、数组等都算有序列的东西

    遍历方式有两种:一种是通过索引遍历(借助内置函数 len() 和 range())

      fruits = ['banana', 'apple', 'mango']

      for index in range(len(fruits)):

      print ('当前水果 :', fruits[index])

      print ("Good bye!")

      一种是不通过索引,直接输出子元素的值

      fruits = ['banana''apple''mango']

      for index in fruits:

      print ('当前水果 :', index)

      print ("Good bye!")

  

原文地址:https://www.cnblogs.com/cui-ting/p/14437033.html