花了两个半天把Python 简介 | 菜鸟教程的内容看完了。
现在是花时间练习代码的时候,只有多敲代码才可能变成老司机啊。
《Learn Python the Hard Way》
从本书开始刷代码:
Ex0: 学会使用powershell, windos的终端。新建一个目录,在目录中创建一个test.py.
python test.py
Ex6: f-string
.format()
type_of_people = 10
x = f"There are {type_of_people} types of people"
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}"
print(x)
print(y)
print(f"I said: {x}")
print(f"I also said: '{y}'")
a = False
joke_evaluation = "Isn't that joke so funny?!{}"
print(joke_evaluation.format(a))
w = "This is the left side of ..."
e = "a string with a right side."
print(w+e)
There are 10 types of people
Those who know binary and those who don't
I said: There are 10 types of people
I also said: 'Those who know binary and those who don't'
Isn't that joke so funny?!False
This is the left side of ...a string with a right side.
Ex8:
formatter = "{} {} {} {}"
print(formatter.format(1, 2, 3, 4))
print(formatter.format("one", "two", "three", "four"))
print(formatter.format(True, False, False, True))
print(formatter.format(formatter, formatter, formatter, formatter))
print(formatter.format(
"Try your",
"Own text here",
"Maybe a poem",
"Or a song about fear"
))
1 2 3 4
one two three four
True False False True
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
Try your Own text here Maybe a poem Or a song about fear
Ex10:
‘’ 中要打“”则用\"
"“中要打''则用\'
\\打印\
\n 转行 \t制表符
''' '''之间可以直接打印' '' \ *等
Ex13:参数 解包 变量
将argv中的变量解包,依次赋予左边的变量名。really神奇的一种赋值方式
Ex14:提示和传递
则每次输入直接用>提示。使用argv模块时:
则必须使用终端的python test.py ss 这种方式传入参数。这是对文件传入参数的方式。可以进行简单的小游戏
Ex15:读取文件
python -m pydoc open 用pydoc查看python的文档,清晰明了
Ex18:
*args 与 脚本的传入参数argv非常像。就是一个[, ,...]
Ex25:
help(ex25)是ex25中的文档 即''' '''之间的文档
ex25的名称,其中的函数以及相应的说明