Python学习笔记

上一篇 / 下一篇  2015-05-07 10:14:31

第一章 字符串
单引号  双引号 三引号 对录入字符串来说都是等价的
1、print函数--打印文本
    print("i said,\"don't do it\"")
i said,"don't do it"

1、\转义字符
2、“”“ 三引号,录入多行文本
3、用加号串联字符串
   >>> "A"+""+"SSDDSDS"
           'ASSDDSDS'
   >>> "a"+"."+"dd"
           'a.dd'
 
4、用print函数连接字符串
     >>> print("AAA","BBB")
             AAA BBB
5、使用格式说明符%S构成字符串
    %s是一个存储器,存储着圆括号中的值(还可以指定要显示的数据格式),序列中的每一项都是用逗号分隔开的字符串
>>> "Jhon %s%s"%("every","man")
'Jhon everyman'
更多字符串格式
>>> "%s %s %10s"%("Jhon","every","Man")
'Jhon every        Man'
>>> "%-5s %s %10s"%("Jhon","every","man")
'Jhon  every        man'
练习:
>>> print("Rock a by baby,\n\ton the tree top,\t\when the windblows\n\t\t\t the cradle will drop")
Rock a by baby,
on the tree top,\when the windblows
the cradle will drop

TAG:

 

评分:0

我来说两句

Open Toolbar