Python 编程学习 chapter 1 编程基础与字符串

来源:互联网 发布:w45ap 软件 编辑:程序博客网 时间:2024/06/07 08:04

1、字符串中,单引号,双引号,三层单引号,三层双引号,等价!

2、引号中存在相同的引号,需要转义。如下:

      " i said ,"you are right!" "  此句会报错,需进行如下修改:" i said ,\"you are right!\" "

      ' you don't do that'  此句会报错,需进行如下修改:' you don\'t do that'

      ......

3、字符串连接

      "hello"+"world"

      "hello""world"

      "hello"+" "+"world"

      "hello"+"."+"world"

      print("hello","world")     此方法,Python 2.7失效

      "hello %s"%("world")

       "%s %s %s"%("John","hello","world")

     "%5s %s %s"%("John","hello","world") 效果如下:'   John hello world'

     "%-5s %s %s"%("John","hello","world")效果如下:'John    hello world'

0 0
原创粉丝点击