刚刚学习Python做的小练习
字符串中是否存在相同的字母
tests = 'abcdefghijklmnopqrstuvwxyza'
def isDuplicate(s):
num = 1
flag = False
for s1 in s:
num += 1
for s2 in s[num:len(s)+1]:
if s2 == s1:
flag = True
print "True"
break
if flag:
break
else:
print "False"
isDuplicate(tests)
回文数的判断
def isPalindromes(s):
midNum = len(s)//2
num = 1
for count in range(0,midNum,1):
if s[count] != s[len(s)-num]:
print "不是回文数"
break
num += 1
else:
print "是回文数"
palindromesString = "abcdefedcba"
isPalindromes(palindromesString)
感受:
Python多变量赋值
a,b="django",2
这个用起来有点难受,感觉多此一举
for的用法有点特别,for else的用法新颖