通过比较两个字符串的值(ASCII字符代码)来比较两个字符串.
null / NULL / Nil / None
应该被视为空字符串如果字符串相等,你的方法应返回true
,如果它们不相等,则返回false
.
JS
"AD","BC" - >相等
"AD","DD" - >不相等
"gf","FG" - >相等
"zz1","" - >相等(两者都被认为是空的)
"ZzZz","ffPFF" - >相等
"kl","lz" - >不相等
null,"" - >相等
def compare(s1,s2):
#your code here
Test.assert_equals(compare("AD", "BC"), True, "\'AD\' vs \'BC\'")
Test.assert_equals(compare("AD", "DD"), False, "\'AD\' vs \'DD\'")
Test.assert_equals(compare("gf", "FG"), True, "\'gf\' vs \'FG\'")
Test.assert_equals(compare("Ad", "DD"), False, "\'Ad\' vs \'DD\'")
Test.assert_equals(compare("zz1", ""), True, "\'zz1\' vs \'\'")
Test.assert_equals(compare("ZzZz", "ffPFF"), True, "\'ZzZz\' vs \'ffPFF\'")
Test.assert_equals(compare("kl", "lz"), False, "\'kl\' vs \'lz\'")
Test.assert_equals(compare(None, ""), True, "\'\' vs \'\'")
Test.assert_equals(compare("!!", "7476"), True, "\'!!\' vs \'7476\'")
点击查看答案
Python基础练习题:数组中的每个值都是数组吗?【难度:1级】–景越Python编程实例训练营,Python自学,Python进阶必备良品
Python进阶练习题:找到Codewars Universe的Nexus【难度:2级】–景越Python编程实例训练营,Python自学,Python进阶必备良品
Python基础练习题:杂乱无章的页面列表【难度:1级】–景越Python编程实例训练营,不同难度Python习题,适合自学Python的新手进阶
编程题:超市排队【难度:2级】–景越Python编程训练之挑战1000道Python面试题(含答案)
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/