Home >Backend Development >Python Tutorial >使用python实现strcmp函数功能示例

使用python实现strcmp函数功能示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 11:29:382077browse

实现这个功能我相信大家一定明白他的意思了,很简单了,下面的代码大家参考使用吧

代码如下:


def strcmp(str1,str2):
        i = 0
        while i                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)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn