判断一串字符串中的大小写,数字,特殊字符的方法
思路:1.输入一串字符
2.判断是什么形式
3.用叠加的方法来计数
4.将记录的数据放进列表或者元组中
str = input('请输入一串字符\n')
# str = '1234asdfQWERT/.;[];.' # 还未完成时 省的每次都要输入
big = 0
small = 0
number = 0
special = 0
def big1():
global big
for i in str:
if i >= 'A' and i <= 'Z':
big += 1
def small1():
global small
for i in str:
if i>='a' and i<='z':
small += 1
def number1():
global number
for i in str:
if i>='0' and i<='9':
number += 1
def special1():
global special
for i in str:
if i >= 'a' and i <= 'z':
a=0
elif i >= 'A' and i <= 'Z':
a=0
elif i >= '0' and i <= '9':
a=0
else:
special += 1
big1()
small1()
number1()
special1()
tu = (big, small, number, special)
print('输出顺序为:大写 小写 数字 特殊')
print(tu)
这一段代码,主要是熟悉怎么使用函数
换汤不换药的另外一个简单的代码
str = input('请输入一串字符\n')
# str = '1234asdfQWERT/.;[];.'
big = 0
small = 0
number = 0
special = 0
for i in str :
if i>='a' and i<='z':
small+=1
elif i>='A' and i<='Z':
big+=1
elif i>='0' and i<='9':
number+=1
else :
special