python基础练习题:比较字符串的字符串【难度:1级】--景越Python编程实例训练营,不同难度Python习题,适合自学Python的新手进阶

python基础练习题:比较字符串的字符串【难度:1级】:

通过比较两个字符串的值(ASCII字符代码)来比较两个字符串.

  • 用于比较将所有字母视为UpperCase
    *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/

你可能感兴趣的:(python基础练习题:比较字符串的字符串【难度:1级】--景越Python编程实例训练营,不同难度Python习题,适合自学Python的新手进阶)