Python2 学习进度
首页 > Learning > Programming   作者:eehello  2015年6月2日 10:31 星期二  浏览:5800  字号:   评论:1 条
时间:2015-6-2 10:31   浏览:5800  评论:1 条 


教程链接:http://pan.baidu.com/s/1qWqlaGG


在每个代码的开头输入 

#coding=utf-8

可以在程序里输出中文

此方法在linux下有效,windows下还没找到简单方法,目前输出中文都是乱码。


2015.06.02

习题6:字符串(string)和文本

#coding=utf-8
x = 'There are %d types of people.' % 10    #定义变量
binary = 'binary'
do_not = 'don`t'
y='Those who know %s and those who %s .' % (binary,do_not)

print x
print y

print 'I said:%r .' %x
print "I also said: '%s' ." % y

hilarious = False
joke_evaluation = 'Isn`t that joke so funny?! %r'

print joke_evaluation % hilarious

w='This is the left side of ...'
e='a string with a right side.'

print w+e  #把w和e相连接后输出
print w,e   #输出w后再输出e,结果里面w和e中间会有一个空格


习题7:更多打印

#coding=utf-8
print "Mary had a little lamb"
print "Its fleece was white as %s." % 'snow'
print "And everywhere that Mary went."
print "." *10 #这个输出是什么意思?连续输出10个’.’

end1="C"
end2="h"
end3="e"
end4="e"
end5="s"
end6="e"
end7="B"
end8="u"
end9="r"
end10='g'
end11="e"
end12="r"

print end1+end2+end3+end4+end5+end6, #加个’,‘的作用为在输出界面不换行
print end7+end8+end9+end10+end11+end12

习题8:打印,打印

#coding=utf-8
formatter = "%r %r %r %r"

print formatter % (1,2,3,4)
print formatter % ("one","two","three","four")
print formatter % (True,False,False,True)
print formatter % (formatter,formatter,formatter,formatter)
print formatter % (
    "I had this thing. have a 'test'",
    "That you could type up right.",
    "But it didn`t sing.",
    "So I said goodnight."
    )


第2行,如果打印此变量,双引号默认不输出。

第5行,输出里面带有双引号,因为在formatter变量的外围已经有一个隐式的双引号,所以此输出的双引号会自动转化为单引号。

第9行,我在输出里面有添加了一个单引号,造成的结果为,这句话外面的双引号顶替掉了formatter变量外围的双引号了,显示为双引号,test的单引号正常显示。但是如果把test的单引号改为双引号,就会报错。

具体的这个双引号、单引号还是不太明白,以上只是我的猜测,等待学会此语言后证实。


2015.06.20

习题9:打印,打印,打印

#coding=utf-8

days = "Mon Tue Wed Thu Fri Sat Sun"
months ="jan\nfeb\nmar\napr\njun\njul\naug"  #看显示结果可以确定“\n”是换行符

print "here are the days:",days
print "there are the months",months

print """             
there`s something going on here.
with the three double-quotes.
we`ll be able to type as much as we like.
even 4 lines if we want, or 5, or 6.
"""

第9行和第14行的作用不清楚,看显示结果,好像是输出“"""”3个双引号之间的内容

习题10:那是什么?

 您阅读这篇文章共花了: 
 本文没有标签!
二维码加载中...
本文作者:eehello      文章标题: Python2 学习进度
本文地址:https://www.eehello.com/?post=178
版权声明:若无注明,本文皆为“点滴记忆---观雨亭”原创,转载请保留文章出处。
eehello2015-06-02 17:38
http://www.cnblogs.com/brooks-dotnet/archive/2013/05/07/3065480.html

返回顶部| 首页| 手气不错| 留言板|后花园

Copyright © 2014-2023 点滴记忆---观雨亭