python没有strcmp函数,不过有cmp不用导入直接使用就可以了。
例如:
 
当然,最好是用python实现 个strcmp函数功能。
代码:
 
#!/usr/bin/python
# www.jb200.com
def strcmp(str1,str2):
        i = 0
        while i<len(str1) and i<len(str2):
                outcome = cmp(str1[i],str2[i])
                if outcome:
                        print outcome
                        return outcome
                i +=1
        return cmp(len(str1),len(str2))
str1='dfdcd'
str2='dfdc'
print strcmp(str1,str2)
print cmp(str1,str2)