新手学python-笨方法学python-ex1

写给某人:有一位同学天天在我耳边念叨Python语言如何如何好(请恕我词穷不知如何复述那个如何如何到底是有多如何如何),所以下定决心要从头开始学习Python了。写代码一直是我的软肋,希望这次能坚持学习,边学边记。

借口就不再找了,总之过完双休之后,昨天礼拜一没有坚持学习,今天继续。找到个学习的教程,笨方法学,打算跟着这个教程学习,边学变做习题边记录。

笨方法学英语-ex1 - 学习记录

[root@lc test]# vi ex1.py     

print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'                                    
"ex1.py" 7L, 184C written
[root@lc test]# 


执行该代码,输入python ex1.py:

[root@lc test]# python ex1.py
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
[root@lc test]# 


习题:
1.让你的脚本再多打印一行。

[root@lc test]# vi ex1-1.py 

print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
print "Let your script print one more line."                                        
"ex1-1.py" 8L, 229C written
[root@lc test]# python ex1-1.py 
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
Let your script print one more line.
[root@lc test]# 

 

2.让你的脚本只打印一行。

[root@lc test]# vi ex1-2.py 

print "Let your script print only one line."
                                                                                                                                
"ex1-2.py" 1L, 45C written
[root@lc test]# python ex1-2.py 
Let your script print only one line.
[root@lc test]# 


3.在一行的起始位置放一个 ‘#’ (octothorpe) 符号。它的作用是什么?自己研究一下。

[root@lc test]# vi ex1-3.py 

print "Hello World!"
#print "Hello Again"
print "I like typing this."
#print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
#print "Let your script print one more line."
"ex1-3.py" 8L, 232C written
[root@lc test]# python ex1-3.py 
Hello World!
I like typing this.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.
[root@lc test]# 

由练习结果可得知:
1.print打印字符串时使用英文的单引号''或者双引号“”,如果本身打印内容里面有单引号则用print" ",如果打印内容本身含有双引号则用print''。
2.‘#’ (octothorpe) 符号的作用是注释。后面的内容不执行。

Tuesday, October 27, 2015 | Python

文章评论

No comments posted yet.

发表评论

Please add 1 and 2 and type the answer here: