虽然前期已通过自学,完成了python基础部份的学习,但是对于实践方面的实操较少。为了让自己在读下一本编程书籍前打下良好的基础,通过《笨办法学python》这本书复习并提高自已的编程能力,以跑例子为主,并进行相关知识点的归纳总结。(pycharm,版本是python3.8。)
Python3与Python2在使用print时区别在于是否需要添加()。
> 习题 1: 第一个程序
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.')
运行结果为:
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.
> 加分习题
> 1.让你的脚本再多打印一行。
print ("I'd much rather you 'not'.")
print("\n")
print ('I "said" do not touch this.')
运行结果:
I'd much rather you 'not'.
I "said" do not touch this.
> 2.让你的脚本只打印一行。
方法一:
print ("Hello World!",end="")
print ("Hello Again" ,end="")
print ("I like typing this." ,end="")
print ("This is fun.",end="")
print ('Yay! Printing.' ,end="")
print ("I'd much rather you 'not'.",end="")
print ('I "said" do not touch this.',end="")
运行结果:
Hello World!Hello AgainI like typing this.This is fun.Yay! Printing.I'd much rather you 'not'.I "said" do not touch this.
方法二:
print("How old are you?",
"How tall are you?",
"How much do you weigh? ")
运行结果:
How old are you? How tall are you? How much do you weigh?
> 3.在一行的起始位置放一个 ‘#’ (octothorpe) 符号。它的作用是什么?自己研究一下。
#的作用就是注释,用于解释代码是怎样的逻辑或者作用,方便自己或者别的程序员阅读代码时能够理解代码的意义。# (井号)跟着的文字是不会被程序执行。只是做一个解释。
print ("Hello World!",end="")
#print默认是打印一行,结尾加换行。end=' '意思是末尾不换行,加空格
print ("Hello Again" )
运行结果:
Hello World!Hello Again