python(三)

花了两个半天把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:参数 解包 变量

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的名称,其中的函数以及相应的说明


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值