defcustom_lower(s):ifnotisinstance(s,str):return"函数中传入的参数不是字符串!"
result=""for i in s:if i>="A"and i<="Z":
result+=chr(ord(i)+32)else:
result+=i
return result
print(custom_lower("Hello,World!你好123"))#执行结果:hello,world!你好123
自定义实现upper()函数:将字符串中所有的字母转换成大写
defcustom_upper(s):ifnotisinstance(s,str):return"函数中传入的参数不是字符串!"
result=""for i in s:if i>="a"and i<="z":
result+=chr(ord(i)-32)else:
result+=i
return result
print(custom_upper("Hello,World!你好123"))#执行结果:HELLO,WORLD!你好123
自定义实现swapcase()函数:大小写互换
defcustom_swapcase(s):ifnotisinstance(s,str):return"函数中传入的参数不是字符串!"
result=""for i in s:if i>="a"and i<="z":
result+=chr(ord(i)-32)elif i>="A"and i<="Z":
result+=chr(ord(i)+32)else:
result+=i
return result
print(custom_swapcase("Hello,World!你好123"))#执行结果:hELLO,wORLD!你好123
自定义实现find()函数:在字符串中查找指定字符串方法一:def find_str1(s,dest_str): if not isinstance(s,str): return "函数中传入的参数%s不是字符串!" %s elif not isinstance(dest_str,str): return "函数中传入的参数%s不是字符串!"...