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


Posted in Python onMarch 25, 2014

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

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完全新手教程
Feb 08 Python
Python中使用socket发送HTTP请求数据接收不完整问题解决方法
Feb 04 Python
python和ruby,我选谁?
Sep 13 Python
PyCharm 设置SciView工具窗口的方法
Jan 15 Python
python实现比对美团接口返回数据和本地mongo数据是否一致示例
Aug 09 Python
Django中的cookie和session
Aug 27 Python
django连接mysql数据库及建表操作实例详解
Dec 10 Python
解决Keras 与 Tensorflow 版本之间的兼容性问题
Feb 07 Python
Python 实现网课实时监控自动签到、打卡功能
Mar 12 Python
opencv+python实现鼠标点击图像,输出该点的RGB和HSV值
Jun 02 Python
在django中查询获取数据,get, filter,all(),values()操作
Aug 09 Python
Python办公自动化PPT批量转换操作
Sep 15 Python
python读写ini文件示例(python读写文件)
Mar 25 #Python
python判断windows隐藏文件的方法
Mar 21 #Python
python解析中国天气网的天气数据
Mar 21 #Python
python实现文件名批量替换和内容替换
Mar 20 #Python
Python读写Redis数据库操作示例
Mar 18 #Python
python实现k均值算法示例(k均值聚类算法)
Mar 16 #Python
python实现保存网页到本地示例
Mar 16 #Python
You might like
PHP实现的比较完善的购物车类
2014/12/02 PHP
ThinkPHP开发框架函数详解:C方法
2015/08/14 PHP
深入浅析用PHP实现MVC
2016/03/02 PHP
CI框架常用经典操作类总结(路由,伪静态,分页,session,验证码等)
2016/11/21 PHP
ThinkPHP 5.x远程命令执行漏洞复现
2019/09/23 PHP
JavaScript 应用技巧集合[推荐]
2009/08/30 Javascript
JQuery+JS实现仿百度搜索结果中关键字变色效果
2011/08/02 Javascript
Json实现异步请求提交评论无需跳转其他页面
2014/10/11 Javascript
JavaScript使用addEventListener添加事件监听用法实例
2015/06/01 Javascript
认识Knockout及如何使用Knockout绑定上下文
2015/12/25 Javascript
总结jQuery插件开发中的一些要点
2016/05/16 Javascript
一览画面点击复选框后获取多个id值的方法
2016/05/30 Javascript
JavaScript编程设计模式之构造器模式实例分析
2017/10/25 Javascript
echarts学习笔记之箱线图的分析与绘制详解
2017/11/22 Javascript
node.js将MongoDB数据同步到MySQL的步骤
2017/12/10 Javascript
jQuery序列化form表单数据为JSON对象的实现方法
2018/09/20 jQuery
element-ui table span-method(行合并)的实现代码
2018/12/20 Javascript
解决vue-cli webpack打包开启Gzip 报错问题
2019/07/24 Javascript
vue自动化路由的实现代码
2019/09/30 Javascript
jQuery实现穿梭框效果
2021/01/19 jQuery
Python比较2个时间大小的实现方法
2018/04/10 Python
Django model update的多种用法介绍
2020/03/28 Python
python3多线程知识点总结
2019/09/26 Python
Django 简单实现分页与搜索功能的示例代码
2019/11/07 Python
tensorflow实现残差网络方式(mnist数据集)
2020/05/26 Python
Python检测端口IP字符串是否合法
2020/06/05 Python
零基础学python应该从哪里入手
2020/08/11 Python
Django数据模型中on_delete使用详解
2020/11/30 Python
Data URI scheme详解和使用实例及图片base64编码实现方法
2014/05/08 HTML / CSS
什么是用户模式(User Mode)与内核模式(Kernel Mode) ?
2015/09/07 面试题
读书小明星事迹材料
2014/05/03 职场文书
2014年度党员自我评议
2014/09/13 职场文书
党员学习群众路线教育实践活动对照检查材料
2014/09/23 职场文书
2014小学年度工作总结
2014/12/20 职场文书
百年孤独读书笔记
2015/06/29 职场文书
python 模拟在天空中放风筝的示例代码
2021/04/21 Python