使用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提取页面内url列表的方法
May 25 Python
浅谈Python的异常处理
Jun 19 Python
Python中super函数的用法
Nov 17 Python
windows10下python3.5 pip3安装图文教程
Apr 02 Python
python队列queue模块详解
Apr 27 Python
Python实现去除列表中重复元素的方法小结【4种方法】
Apr 27 Python
Python数据可视化教程之Matplotlib实现各种图表实例
Jan 13 Python
python 列表推导式使用详解
Aug 29 Python
win10子系统python开发环境准备及kenlm和nltk的使用教程
Oct 14 Python
Pycharm debug调试时带参数过程解析
Feb 03 Python
Python pandas如何向excel添加数据
May 22 Python
详解Python flask的前后端交互
Mar 31 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
深入phpMyAdmin的安装与配置的详细步骤
2013/05/07 PHP
php 获取SWF动画截图示例代码
2014/02/10 PHP
thinkPHP5框架中widget的功能与用法详解
2018/06/11 PHP
php统计数组不同元素的个数的实例方法
2019/09/26 PHP
Avengerls vs KG BO3 第二场2.18
2021/03/10 DOTA
Mootools 1.2教程 Fx.Tween的使用
2009/09/15 Javascript
ExtJS DOM元素操作经验分享
2013/08/28 Javascript
IE网页js语法错误2行字符1、FF中正常的解决方法
2013/09/09 Javascript
使用jQuery中的when实现多个AJAX请求对应单个回调的例子分享
2014/04/23 Javascript
JavaScript判断变量是否为空的自定义函数分享
2015/01/31 Javascript
javascript实现的图片切割多块效果实例
2015/05/07 Javascript
jquery选择器简述
2015/08/31 Javascript
Vue.js表单控件实践
2016/10/27 Javascript
vue 注册组件的使用详解
2018/05/05 Javascript
微信小程序scroll-view实现字幕滚动
2018/07/14 Javascript
Vue.js中的extend绑定节点并显示的方法
2019/06/20 Javascript
Vue-cli项目部署到Nginx服务器的方法
2019/11/01 Javascript
Vue.js实现可编辑的表格
2019/12/11 Javascript
JS JQuery获取data-*属性值方法解析
2020/09/01 jQuery
在Django的上下文中设置变量的方法
2015/07/20 Python
Python切换pip安装源的方法详解
2016/11/18 Python
python实现飞机大战
2018/09/11 Python
Python类和对象的定义与实际应用案例分析
2018/12/27 Python
python 去除二维数组/二维列表中的重复行方法
2019/01/23 Python
Django框架 querySet功能解析
2019/09/04 Python
Python3实现个位数字和十位数字对调, 其乘积不变
2020/05/03 Python
python 字符串格式化的示例
2020/09/21 Python
英国百安居装饰建材网上超市:B&Q
2016/09/13 全球购物
高三毕业典礼主持词
2014/03/27 职场文书
县委常委班子对照检查材料思想汇报
2014/09/28 职场文书
简易离婚协议书(范本)
2014/10/25 职场文书
党员教师群众路线思想汇报范文
2014/10/28 职场文书
大学生助学金感谢信
2015/01/21 职场文书
2015年社区党务工作总结
2015/04/21 职场文书
农村环境卫生倡议书
2015/04/29 职场文书
全国劳模先进事迹材料(2016精选版)
2016/02/25 职场文书