Python学习日志-1

这是个记录我学习Python3心酸之路的日志,参考书目是《Python编程:从入门到实践》,我在sublime里配置Python3后就简单实用sublime打代码,今天分享的是第二章的要点和课后习题的参考代码。

要点:

1、print()的使用.

2、变量命名规则.

3、字符串的定义和使用.

4、空白的添加和删除:\t、\n、rstrip()、lstrip()、strip().

5、整数、浮点数的概念.

6、str() 的使用.

7、注释的使用(“#”)

8、Python之禅


参考代码:

2-1

message = "JHhhha is me"
print(message)

运行结果:

JHhhha is me
[Finished in 0.0s]

2-2

message = "JHhhha is me"
print(message)
message = "Zhan Jianzhou is my roommate"
print(message)

运行结果:

JHhhha is me
Zhan Jianzhou is my roommate
[Finished in 0.0s]

2-3

user_name = "JHhhha"
print("Hello " + user_name + ", would you like to learn some Python today?")

运行结果:

Hello JHhhha, would you like to learn some Python today?
[Finished in 0.0s]

2-4

name_case = "JHhhha"
print(name_case.upper())
print(name_case.lower())
print(name_case.title())

运行结果:

JHHHHA
jhhhha
Jhhhha
[Finished in 0.0s]

2-5

saying = '"The darkest hour is that before the dawn."'
name = "Fuller"
print(name + " once said, " + saying)

运行结果:

 
 
Fuller once said, "The darkest hour is that before the dawn."
[Finished in 0.0s]

2-6

famous_person = "Fuller"
message = famous_person + " once said," + '" The darkest hour is that before the dawn"  '
print(message)

运行结果:

 
  
Fuller once said," The darkest hour is that before the dawn"  
[Finished in 0.0s]

2-7

famous_person = "\tFuller\n"
print(famous_person)
print(famous_person.strip())
print(famous_person.rstrip())
print(famous_person.lstrip())

运行结果:

 
  
	Fuller


Fuller
	Fuller
Fuller


[Finished in 0.0s]

2-8

print(1 + 7)
print(2 * 4)
print(10 - 2)
print(8 / 1)
print(8 // 1)

运行结果:

 
 
8
8
8
8.0
8
[Finished in 0.0s]

2-9

my_number = 7
print("my favourite number is " +  str(my_number) + ".")

运行结果:

 
 
my favourite number is7.
[Finished in 0.0s]

2-10

#这个程序说明了我最喜欢的数字是7
my_number = 7
print("my favourite number is " +  str(my_number) + ".")

运行结果:

 
 
my favourite number is7.
[Finished in 0.0s]

2-11 Python之禅

# Python之禅
import this

运行结果:

 
 
The Zen of Python, by Tim Peters


Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
[Finished in 0.0s]
今天的分享就是这些了,还不太会排版,请见谅……


猜你喜欢

转载自blog.csdn.net/weixin_38224302/article/details/79512503