开发者社区> 问答> 正文

尝试检测变量/字符串是否在Python中混合大小写

我正在尝试编写一个简单的程序来检测字符串是否为大写,小写或大小写混合。

我尝试了x.ismixed,但是没有用

我也尝试过x == mixed.case

这是代码:

x = input('Loud: ')

if x.isupper():

print("Quiet:", x.lower())

elif x.ismixed():

print (x.lower)

else:

print (x.lower)

Input: HEllO ThEre Output: hello there.

展开
收起
游客6qcs5bpxssri2 2019-09-27 09:51:30 1737 0
1 条回答
写回答
取消 提交回答
  • 这不是错误,只是您没有使用调用函数()。另外,ismixed它不是内置的,您必须自己编写:

    def ismixed(s):

    return any(c.islower() for c in s) and any(c.isupper() for c in s)
    

    x = input('Loud: ')

    if x.isupper():

    print("Quiet:", x.lower())

    elif ismixed(x):

    print(x.lower())

    else:

    print(x.lower())

    2019-09-28 18:30:24
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载