zoukankan      html  css  js  c++  java
  • Python字符串

    #什么是字符串?字符串是一系列字符,用引号括起来(单引号,双引号)
    str1="这是字符串1"
    str2='这是字符串2'
    修改字符串大小写
    name="Itester coco"
    print(name.title())
    #title()以首字母大写的方式显示每个单词(即每个首字母都改为大写)
    
    print(name.upper())
    print(name.lower())
    拼接字符串
    #Python中使用 +来拼接字符串
    first_name="ITester"
    last_name="coco"
    full_name=first_name+" "+last_name
    print(full_name)
    #拼接消息:个性化消息
    first_name="ITester"
    last_name="coco"
    full_name=first_name+" "+last_name
    msg="Hello,"+full_name.title()+"!"
    print(msg)
    使用制表符或换行符添加空白信息
    制表符:	
    换行符:
    #空白泛指任何非打印字符,如空格、制表符、换行符
    
    print("	python")
    print("Languages:
    Python
    Java
    C")
    print("Languages:
    	Python
    	C
    	Java
    	PHP")
    删除空白
    #暂时删除
    msg="python php "
    print(msg)
    print(msg.rstrip())
    
    #永久删除
    msg="python php "
    msg=msg.rstrip()
    print(msg)

    #删除左右两边的空白
    msg=" pyhont php "
    print(msg.strip())
    字符串语法错误示例
    #成对的单引号包含单引号
    msg='ITester's coco'

    想获取更多最新干货内容快来星标 置顶 关注我

     



    测试交流Q群:727998947

  • 相关阅读:
    C# 委托/Func() 中 GetInvocationList() 方法的使用 | 接收委托多个返回值
    蒋廷黻著《中国近代史》-中国近代屈辱史读后感
    ASP.NET Core 上传多文件 超简单教程
    Python
    Python
    Python
    Python
    Python
    Python
    Python
  • 原文地址:https://www.cnblogs.com/ITester520/p/13372870.html
Copyright © 2011-2022 走看看