python(三)

来源:互联网 发布:js 获取html属性值 编辑:程序博客网 时间:2024/06/07 01:44

花了两个半天把Python 简介 | 菜鸟教程的内容看完了。

现在是花时间练习代码的时候,只有多敲代码才可能变成老司机啊。

《Learn Python the Hard Way》

从本书开始刷代码:

Ex0: 学会使用powershell, windos的终端。新建一个目录,在目录中创建一个test.py.

        python test.py

Ex6: f-string

         .format()

        

type_of_people = 10x = 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 = Falsejoke_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 peopleThose who know binary and those who don'tI said: There are 10 types of peopleI also said: 'Those who know binary and those who don't'Isn't that joke so funny?!FalseThis 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 4one two three fourTrue False False True{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}Try your Own text here Maybe a poem Or a song about fear

Ex10:

‘’ 中要打“”则用\"

"“中要打''则用\'

\\打印\

\n 转行  \t制表符

'''  '''之间可以直接打印'  ''  \ *等


Ex13:参数 解包 变量

script, first, second, third = argv
将argv中的变量解包,依次赋予左边的变量名。really神奇的一种赋值方式

Ex14:提示和传递

prompt = '> '
likes = input(prompt)
则每次输入直接用>提示。使用argv模块时:

script, user_name = argv
则必须使用终端的python test.py ss 这种方式传入参数。这是对文件传入参数的方式。可以进行简单的小游戏

Ex15:读取文件

python -m pydoc open 用pydoc查看python的文档,清晰明了

Ex18:

*args  与 脚本的传入参数argv非常像。就是一个[, ,...]
Ex25:

help(ex25)是ex25中的文档 即''' '''之间的文档

ex25的名称,其中的函数以及相应的说明


原创粉丝点击