本笔记都是用python来演示数据结构和算法的示例,万变不离其宗,其他语言的数据结构和算法的思想都是相同的,只不过是换了一种表现方式而已。
###String String实际开发也经常用到,这里总结下Python 中字符串常用的方法。
s1 = str()# in python `''` or `""` is the sames2 = "shaunwei" # 'shuanwei's2len = len(s2)# last 3 charss2[-3:] # weis2[5:8] # weis3 = s2[:5] # shauns3 += 'wei' # return 'shaunwei'# list in python is same as ArrayList in javas2list = list(s3)# string at index 4s2[4] # 'n'# find index at firsts2.index('w') # return 5, if not found, throw ValueErrors2.find('w') # return 5, if not found, return -1