zoukankan      html  css  js  c++  java
  • 笨办法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则不会

  • 相关阅读:
    CentOS/RHEL 查看用户登陆信息
    PAM
    块存储
    ECS
    SQL 基础应用
    MySQL 基础管理
    MySQL 体系结构
    JSON对象
    设置dom节点属性的代码优化
    Ext框架下的元素拖动
  • 原文地址:https://www.cnblogs.com/p36606jp/p/7544175.html
Copyright © 2011-2022 走看看