使用python实现strcmp函数功能示例
使用python实现strcmp函数功能示例
发布时间:2016-12-28 来源:查字典编辑
摘要:实现这个功能我相信大家一定明白他的意思了,很简单了,下面的代码大家参考使用吧复制代码代码如下:defstrcmp(str1,str2):i=...

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

复制代码 代码如下:

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)

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新python学习
热门python学习
脚本专栏子分类