社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python 基础视频课 (本篇免费)

王的机器 • 3 年前 • 394 次点击  


今年初结束的 Python 基础课反响不错,但是报名的人数远没有到达我的预期。我自己花了很多的心血来这门课,觉得这种优质内容应该让更多人看到。


11 节课以 11 篇文章发出,每节课有视频讲解,有精美 PPT 分享,有 Jupyter Notebook 代码分享。因为优质原创内容不易,因此会采用微信付费形式。



整个 Python 基础内容 11 节课可以结构化为六点:


  1. 编程概论

  2. 数据结构

  3. 流程控制

  4. 函数用法

  5. 对象和类

  6. 高级特征


思维脑图如下:



下面用中英文来介绍这六大模块。




模块一:编程概论





编程概论:学习任何一种编程语言,我们都需要了解一些概论。类比计算机语言和人类语言,学习语言首先要了解其词汇语法,再开始讲故事


  • 词汇包括保留字(keyword)和变量名(variable name)

  • 语法包括缩进冒号等等

  • 故事可由三种方式来演绎,按顺序讲;按条件讲;重复


了解完概论就可以了解所有编程语言中最重要的一环,数据


I draw an analogy between human language and Python language. When human learn how to speak, they start with the vocabulary and syntax to make up sentences; while in Python, we start to learn the keywords and syntax to make up statements. Human use sentences to make story, but to be a good storyteller, they should use a mixed approach of organizing sentences in sequence, by conditions and with repetitions. The same approach applies to write program that we can implement the statements in sequence, by conditions and with repetitions







模块二:数据结构





数据:数据的重要性不需要多讲,在 Python 中数据可分两大类:


  • 元素型:整数、浮点、布尔、None

  • 容器型:字符串、元组、列表、字典、集合


数据会被命名成变量,变量(词)之间会发现联系(句子),当你试着「用词造句讲故事」的时候,你实际创建了一个流程,而流程需要控制。


For any programming languages, we should touch the Data Structure first. In Python, thereare two generic types, namely, element-type and container-type.  In the former, we have integer, floating point, Boolean and NoneType, and they store a value, while in the latter, we have stringtuplelistdictionary and set, and they store a collection of values in various formats. As you can see, round, square, and curly bracket shave distinct meanings when it comes to the container-type data. Beyond that, there is a bunch of Collections designed for specialized purposes.







模块三:流程控制






流程类比三种演绎故事的形式,代码也可以按顺序写、按条件写if、重复写while, for,这些都叫做流程控制,当然在运行不出错的时候。如果出错了需要异常处理(try, except)。因此流程控制可细分


  • 按顺序:一句一句写

  • 按条件:用 if 语句

  • 按重复

    • 用 for 循环 - 当循环次数事先知道

    • 用 while 循环 - 当循环次数事先不知道

  • 要纠正:用 try, except, else, finally 语句


当你想重复使用一组语句时,你需要考虑函数


So far everything we have seen has only consisted of sequential execution, but the world is more complicated than that. Control Flow is where the rubber really meets the road in programming. Without it, a program is simply a list of statements that can only be sequentially executed. With it, you can execute certain code blocks conditionally and/or repeatedly. In a real world, we need “if statement” to perform decision-making that allows for conditional execution of a group of statements based on the value of an expression, and we need “for loop”and “while loop” to perform definiteand indefinite iterations.


When the program is “out of control”, weneed to identify the errors first and handle the exceptions, and hopefully regain the control.







模块四:函数用法






函数:Python 定义函数有两种方式:


  1. 用 def  定义普通函数

  2. 用 lambda 定义匿名函数


Python 把函数当成「一等公民」,即可把函数当成变量使用,进而可以定义高阶函数(普通函数和匿名函数都属于低阶函数):


  • 把函数当成输入参数

  • 把函数当成输出结果


介绍完数据和函数后,我们可得出


  • 如果只处理数据,将其存储在列表,字典或其他数据中

  • 如果只处理行为,而没有存储数据,则使用函数更合适


如果同时要处理到数据和行为呢?考虑对象


So far everything we have been using are simple and single-use code blocks. To reuse the codes, we need to consider Functions. A function should do one thing only and do it really well. We have two ways to create functions, using def keyword for normal functions, and lambda keyword for anonymous functions. Functions are first-class citizens in Python. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions.







模块五:类和对象






对象和类对象是既具有数据又具有行为的实例,而类是对象的描述。变量函数是零散的,而对象将它们集合起来,


  • 在对象里也有变量,用来存储数据,这时变量又称字段 fields) 

  • 在对象里也有函数,用来操作数据,这时函数又称方法methods


字段和方法统称为类的属性attributes)。


基于对象编程叫做面向对象编程」,里面的知识点包括:实例变量、类变量、实例方法、类方法、静态方法、继承、多态、魔法方法、属性装饰器等。


So far we have designed program around functions or blocks of statements which manipulate data. This is called the procedure programming. There is another way of organizing your program which is to combine data and functionality and wrap it inside something called an object. This is called the Object-Oriented Programming, or OOP for short.


Classes and objects are thetwo main aspects of OOP. A class creates a new type where objects are instancesof the class.


Objects can store data using ordinary variables that belong to the class, called as fields. Objects can also have functionality by using functions that belong the class, called methods.


This terminology is important because it helps us to differentiate between functions and variables which are independent and those which belong to a class or object. Collectively, the fields and methods are referred to as the attributes of that class. Four of the benefits of OOP are encapsulationinheritance, polymorphism and composition.







模块六:高级特征






高级特征:这是都是些锦上添花的东西,包括格式化字符串、正则表达式、解析表达式、生成器、迭代器和装饰器等等。


Till now, all essential topics have been covered.  Here are some advanced topics.

 

String Formatting are to beautify output string given a pattern, Regular Expressions are used to match and extract string given a pattern, and all we need to learn is how to represent the pattern.


Comprehensions are just for loops and if statements over a collection but expressed in a more compactsyntax.

 

Iterator is a stateful object that will produce the next value when called. Iterable is a stateless object that can be looped with.Iterators are always iterables, but iterables are not always iterators.


Generator is iterator. Two ways of creating generator are generator functions and generator expressions. Normal functions use return statement, while generator functions useyield statement.


List comprehensions use square brackets, while generator expressions use round brackets. A list can be iterated multiple times, a generator is single use. A list is a collection of values, whilea generator is a recipe for producing values.

 

Decorator wraps a function,modifying its behavior without modifying itself. It is a higher order function that takes function as argument and return another function.





最后再强调一次在这门课中学习新知识的四种方法:


  1. 系统化(systematize)零散知识来融会贯通(connect the dots)

  2. 故事化(dramatize)晦涩概念来直观感受(gain the intuitions)

  3. 抽象化(generalize)特定细节的来掌握本质(grasp the essences

  4. 可视化(visualize)复杂关系的来揭开面纱(demystify the processes)


在接下来的 11 篇文章中,我会分享涵盖上述六大模块的 11 节课。Enjoy!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/73452
 
394 次点击