zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

Python 使用 实现 Python 函数 功能 示例 strcmp
2023-06-13 09:15:24 时间

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

复制代码代码如下:

defstrcmp(str1,str2):
       i=0
       whilei<len(str1)andi<len(str2):
               outcome=cmp(str1[i],str2[i])
               ifoutcome:
                       printoutcome
                       returnoutcome
               i+=1
       returncmp(len(str1),len(str2))
str1="dfdcd"
str2="dfdc"

printstrcmp(str1,str2)
printcmp(str1,str2)