1. 程式人生 > >python的基本使用練習

python的基本使用練習

name = "hello java hello python hello word hello life"
# print (name.find("word", 0, len(name)))
# print (name.index("word", 0, len(name)))
# print (name.count(" ",0, len(name)))
# print (name.replace("hello","liufangyun",name.count("hello")))
# print (name.split(java=" ",2))
# print(name.capitalize())
# print (name.title())
# print (name.startswith("hello"))
# print (name.endswith("life"))
# print (name.lower())
# print (name.upper())
# print (name.ljust(10))
# print (name.center(10))
# print (name)
# print (name.lstrip())
# print (name.lfind("java",0,len(name)))
# print (name.partition("java"))
# print (name.rpartition("java"))
# print (name.splitlines())
# print (name.isalnum())
# print (name.isdigit())
# print (name.isspace())
# print (name.join("list"))
# print (len(name))
# s=["sfds","12","3343","dvcedre344"]
# for i in s:
#     print i
# print len(s)
# a=[2,3,4]
# s.append("hege")
# b=[3,4,5,6]
# s.append(b)
# s.append(a)
# print (s)
# d=[0,8,7,6]
# s.insert(0,8)
# print s
# if 9 not in s:
#     print ("zailibian")
# else:
#     print "bucunzai"

s = ["a","b",'c','a','b']
print (s.index('b',1,3))
print (s.count('b'))
print (s.count("s"))
# del s[1]
print s
s.reverse()
print s
s.sort()
print s
s.sort(reverse=True)
print s

for i ,chr in enumerate(s):
    print i,chr