python知识点-->字符串相关处理及其的应用

来源:互联网 发布:php开发app 编辑:程序博客网 时间:2024/05/17 04:57
1.双引号的作用:"Alice's cat",如果是'Alice's cat',“'”后字符无效
2.转义字符:\' , \ ",  \t,  \n, \\。
3.原始字符串:字符串前加r
4.字符串切片,字符串in 与 not in 操作符
5.字符串方法:upper(),lower(),join(),split()
6.字符串检查
   isupper(),islower()  检查是否全大或小写 
   isalpha() 检查是否包含字母
   isalnum() 检查是否包含字母,数字
   isdecimal() 检查是否只包含数字字符
   isspace()   检查是否包含空格,制表符,换行符

   istitle()   检查是否为首字母大写的,后面都是小写的字符

 都是非空,检查满足条件返回True,否则False

   startswith(),endswith()  检查开始或末端字符串

实现能检测你输入字符串类别的示范程序





while True :
    print('Enter your age:')
    age = input()
    if age.isdecimal():
        break
    print('please enter a number for your age.')
    
while True :
    print('select a new passward ')
    password = input()
    if password.isalnum():
        break

    print('passwords can only have letters and numbers')


7.为了让输出界面好看些,有设置调整字符串对齐方式rjust(),ljust(),center()。
   删除空白字符的strip(),rstrip(),lstrip()




0 0
原创粉丝点击