• 笨办法06字符串(string)和文本


    代码如下:

     1 # coding : utf-8
     2 x = "There are %d types of people." % 10
     3 binary = "binary"
     4 do_not = "don't"
     5 y = "Those who know %s and those who %s." % (binary, do_not)
     6 
     7 print x
     8 print y 
     9 
    10 print "I said: %r." % x
    11 print "I also said: %s." % y #将原代码中的‘’单引号删去了,与%r的打印结果做对比
    12 
    13 hilarious = False
    14 joke_evaluation = "Isn't that joke so funny?! %r"
    15 
    16 print ( joke_evaluation % hilarious )
    17 
    18 w = "This is the left side of..."
    19 e = "a string with a right side."
    20 
    21 print w + e 

    运行结果:


    %r是repr;%s是str;前者是被repr处理后的string对象,后者直接是string对象。 使用%r打印出的是字符串会带上引号‘’,使用%s则不会

  • 相关阅读:
    小猫爬山
    方格取数
    Bash 脚本编程
    树链剖分学习笔记
    输入输出优化
    没有上司的舞会
    线性dp 之 麻烦的聚餐
    飞翔
    挖地雷
    The Prices
  • 原文地址:https://www.cnblogs.com/p36606jp/p/7544175.html
Copyright © 2020-2023  润新知