使用较大(>;)或较小(<;)运算符将一个字符串与另一个字符串进行比较并获得true或false的确切含义是什么,如下面的代码:
shopping_list=['heineken', 'patagonia', 'backer', 'austria', 'heisenbhan']
im_drinking='heineken'
for beer in shopping_list:
if beer==im_drinking:
print('yes, special one.')
elif beer>im_drinking:
print('good one')
else:
print('not this one, but I like it to')
这是我运行代码时得到的结果:
yes, special one.
good one
not this one, but I like it to
not this one, but I like it to
good one
假设str1是“简”,str2是“杰克”。比较了str1和str2的前两个字符(J和J)。因为它们相等,所以比较后两个字符。因为它们也是相等的,所以对第三个两个字符(n和k)进行比较。因为“n”的ASCII值大于“k”,所以str1大于str2。你知道吗
相关问题 更多 >
编程相关推荐