【Python3 笔记】《笨办法学Python》


  • 平台:Windows 10
  • Python 版本:3.8
  • 电子书资源受版权原因无法上传 /sad


  • 字符串表示:' '" " 可以相互嵌套使用;

    // 示例
    print("I'd much rather you 'not'.")
    print('I "said" do not touch this.')


  • 字符串嵌入变量:

    法一:在引号(单双引号都行)前添加字母 f 表示 format ,变量用 {} 嵌入;
    法二:引号中使用 {argc1} {argc2} 在引号后添加 .format({argc1=value1}, {argc1=value2});

    // 示例
     my_height = 168  # cm
     my_weight = 57  # kg
     total = my_age + my_height + my_weight
     print(f'If I add {my_age}, {my_height}, {my_weight} I get {total}.')
     print("If I add {age}, {height}, {weight} I get {tot}."
     		.format(age=my_age, weight=my_weight, height=my_height, tot=total))


  • 函数使用*args接收不确定数量的参数:

    // 示例
    def print_multi(*args):
        for i, arg in enumerate(args):
            print(f"arg_{i}: {arg}")
    print_multi("Shaw", "Feed", "jjj")
    print_multi("Morton", "Wang")


  • 命名规则:

    Class —— “camel case” : SuperGoldFactory

    Functions —— “underscore format” : my_awesome_hair

  • Code a little, run a little, fix a little.

  • Only idiots are slaves to rules all the time.


When to Use Inheritance or Composition

The question of “inheritance versus composition” comes down to an attempt to solve the problem of reusable code. You don’t want to have duplicated code all over your software, since that’s not clean and efficient. Inheritance solves this problem by creating a mechanism for you to have implied features in base classes. Composition solves this by giving you modules and the capability to call functions in other classes. If both solutions solve the problem of reuse, then which one is appropriate in which situations? The answer is incredibly subjective, but I’ll give you my three guidelines for when to do which:

  1. Avoid multiple inheritance at all costs, as it’s too complex to be reliable. If you’re stuck with it, then be prepared to know the class hierarchy and spend time finding where everything is coming from.

  2. Use composition to package code into modules that are used in many different unrelated places and situations.

  3. Use inheritance only when there are clearly related reusable pieces of code that fit under a single common concept or if you have to because of something you’re using.

Do not be a slave to these rules. The thing to remember about object-oriented programming is that it is entirely a social convention programmers have created to package and share code. Because it’s a social convention, but one that’s codified in Python, you may be forced to avoid these rules because of the people you work with. In that case, find out how they use things and then just adapt to the situation.

How to Learn Any Programming Language

  1. Get a book or some introductory text about the language.
  2. Go through the book and type in all of the code making all of it run.
  3. Read the book as you work on the code, taking notes.
  4. Use the language to implement a small set of programs you are familiar with in another language.
  5. Read other people’s code in the language, and try to copy their patterns.

The final thing to remember about learning a new language is this: Don’t be a stupid tourist. A stupid tourist is someone who goes to another country and then complains that the food isn’t like the food at home. “Why can’t I get a good burger in this stupid country!?” When you’re learning a new language, assume that what it does isn’t stupid, it’s just different, and embrace it so you can learn it.

已标记关键词 清除标记
<p> <span style="color:#333333;"> </span> </p> <p style="font-family:"color:#3D3D3D;font-size:16px;background-color:#FFFFFF;"> 您观看课程习后<br /> 免费入群领取【超全Python资料包+17本习电子书】 </p> <p style="font-family:"color:#3D3D3D;font-size:16px;background-color:#FFFFFF;"> <img src="https://img-bss.csdn.net/201909261013197021.jpg" alt="" /> </p> <br /> <p> <br /> </p> <p> <span style="color:#333333;">python编程入门,针对0基础就python语言基础语法的各个点逐步讲解,由浅入深,通俗易懂,层层深入。</span> </p> <p> <span style="color:#333333;"> </span> </p> <p style="font-size:14px;color:#333333;"> 课程亮点: </p> <p style="font-size:14px;color:#333333;"> 1,对于编程0基础的同或者想把python作为第二门编程语言的同十分适合。 </p> <p style="font-size:14px;color:#333333;"> 2,生动形象,浅显易懂,清晰明了。 </p> <p style="font-size:14px;color:#333333;"> 3,针对基础语法详细讲解,构建python编程的基础能力。 </p> <p style="font-size:14px;color:#333333;"> <br /> </p> <p style="font-size:14px;color:#333333;"> 课程内容: </p> <p style="font-size:14px;color:#333333;"> python基础习课程,从搭建环境到判断语句,再到基础的数据类型,之后对函数进行习掌握,熟悉文件操作,初步构建面向对象的编程思想,最后以一个案例带领同进入python的编程殿堂 </p> <p style="font-size:14px;color:#333333;"> <br /> </p> <p style="font-size:14px;color:#333333;"> 适用人群: </p> <p style="font-size:14px;color:#333333;"> 1、希望未来从事IT行业编程方向工作的小伙伴进行入门习。 </p> <p style="font-size:14px;color:#333333;"> 2、希望以后从事人工智能方向工作需要掌握python编程语言的人群。 </p> <p style="font-size:14px;color:#333333;"> <br /> </p> <p style="font-size:14px;color:#333333;"> 课程目录介绍: </p> <p style="font-size:14px;color:#333333;"> 1. python入门-环境搭建和第一个python程序 </p> <p style="font-size:14px;color:#333333;"> 2. python入门-数据类型、输入输出以及运算符 </p> <p style="font-size:14px;color:#333333;"> 3. 流程控制-判断语句 </p> <p style="font-size:14px;color:#333333;"> 4. 流程控制-循环 </p> <p style="font-size:14px;color:#333333;"> 5. 数据序列-字符串 </p> <p style="font-size:14px;color:#333333;"> 6. 数据序列-列表和元祖 </p> <p style="font-size:14px;color:#333333;"> 7. 数据序列-字典和集合 </p> <p style="font-size:14px;color:#333333;"> 8. 数据序列-公共操作以及推导式 </p> <p style="font-size:14px;color:#333333;"> 9. 函数上 </p> <p style="font-size:14px;color:#333333;"> 10. 函数下 </p> <p style="font-size:14px;color:#333333;"> 11. 函数进阶上 </p> <p style="font-size:14px;color:#333333;"> 12. 函数进阶下 </p> <p style="font-size:14px;color:#333333;"> 13. 文件操作 </p> <p style="font-size:14px;color:#333333;"> 14. 面向对象-基础 </p> <p style="font-size:14px;color:#333333;"> 15. 面向对象-继承 </p> <p style="font-size:14px;color:#333333;"> 16. 面向对象-其他 </p> <p style="font-size:14px;color:#333333;"> 17. 异常处理 </p> <p style="font-size:14px;color:#333333;"> 18. 模块和包 </p> <p style="font-size:14px;color:#333333;"> 19. 综合案例 </p> <br />
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页