Home Backend Development Python Tutorial Zhonggu Education Python video tutorial resource recommendation

Zhonggu Education Python video tutorial resource recommendation

Sep 01, 2017 pm 02:22 PM
python Tutorial resource

"Zhonggu Education Python Video Tutorial" is an introductory tutorial for Python development. It will introduce the characteristics and scope of application of the Python language, Python's basic data types, conditional judgments and loops, functions, and Python's unique slices and lists. Generative expression. Hopefully this python tutorial will get you started quickly and write simple Python programs.

Zhonggu Education Python video tutorial resource recommendation

Course playback address: http://www.php.cn/course/501.html

The teacher’s teaching style:

The teacher’s lectures are simple, clear, layer-by-layer analysis, interlocking, rigorous argumentation, rigorous structure, and use the logical power of thinking to attract students’ attention Strength, use reason to control the classroom teaching process. By listening to the teacher's lectures, students not only learn knowledge, but also receive thinking training, and are also influenced and influenced by the teacher's rigorous academic attitude

The more difficult point in this video is object-oriented-class and object Now:

Everything in Python is an object. Classes provide a mechanism for creating new types of objects. In this tutorial, we will not talk about the basic knowledge of classes and object-oriented programming, but focus on better understanding Python object-oriented programming. Suppose we use new style Python classes, which inherit from the object parent class.
Define class

The class statement can define a series of attributes, variables, and methods, which are shared by instance objects of this class. A simple class definition is given below:

class Account(object):
  num_accounts = 0
  
  def __init__(self, name, balance):
   self.name = name
   self.balance = balance
   Account.num_accounts += 1
  
  def del_account(self):
   Account.num_accounts -= 1
  
  def deposit(self, amt):
   self.balance = self.balance + amt
  
  def withdraw(self, amt):
   self.balance = self.balance - amt
  
  def inquiry(self):
   return self.balance
Copy after login


The class definition introduces the following new objects:

Class Object
Instance Object
Method object

Class object

When a class definition is encountered during program execution, a new namespace will be created. The namespace contains the name bindings of all class variables and method definitions. Certainly. Note that this namespace does not create a new local scope that class methods can use, so accessing variables within methods requires fully qualified names. The Account class in the previous section demonstrates this feature; the method that attempts to access the num_of_accounts variable needs to use the fully qualified name Account.num_of_accounts, otherwise, if the fully qualified name is not used in the __init__ method, the following error will be raised:

class Account(object):
 num_accounts = 0
  
 def __init__(self, name, balance):
  self.name = name
  self.balance = balance
  num_accounts += 1
  
 def del_account(self):
  Account.num_accounts -= 1
  
 def deposit(self, amt):
  self.balance = self.balance + amt
  
 def withdraw(self, amt):
  self.balance = self.balance - amt
  
 def inquiry(self):
  return self.balance
  
>>> acct = Account('obi', 10)
Traceback (most recent call last):
 File "python", line 1, in <module>
 File "python", line 9, in __init__
UnboundLocalError: local variable &#39;num_accounts&#39; referenced before assignment
Copy after login

At the end of the execution of the class definition, a class object will be created. The scope that was in effect before entering the class definition is now restored, and the class object is bound to the class name in the class definition header.

Let’s deviate from the topic first. You may ask if the class created is an object, then what is the class of the object? . Consistent with the Python philosophy that everything is an object, class objects do have a class, which is the type class in Python's new style classes.

>>> type(Account)
<class &#39;type&#39;>
Copy after login

To confuse you a little more, the type of Account type is type. The type class is a metaclass used to create other classes, which we will introduce later in the tutorial.

Class objects support attribute reference and instantiation. Properties are referenced via standard dot syntax, i.e. object followed by a period, then the property name: obj.name. Valid property names are all variable and method names that appear in the class namespace after the class object is created. For example:

>>> Account.num_accounts
>>> 0
>>> Account.deposit
>>> <unbound method Account.deposit>
Copy after login

Class instantiation uses function notation. Instantiation will call the class object without parameters like a normal function, such as the Account class below:

>>> Account()
Copy after login

After the class object is instantiated, the instance object will be returned. If the __init__ method is defined in the class, it will be called , the instance object is passed as the first parameter. This method will perform user-defined initialization process, such as initialization of instance variables. For the Account class, for example, the account name and balance will be set, and the number of instance objects will be increased by 1.
Instance Object

If the class object is a cookie cutter, the cookie is the result of instantiating the class object. All valid operations on instance objects are references to property, data, and method objects.
Method object

Method object is similar to function object. If x is an instance of the Account class, x.deposit is an example of a method object. There is an additional parameter in the method definition, self. self points to the class instance. Why do we need to pass instances as parameters to methods? Method calls best illustrate:

>>> x = Account()
>>> x.inquiry()
10
Copy after login

What happens when an instance method is called? You should note that x.inquiry() is called without parameters, although the method definition contains the self parameter. So what exactly is happening with this parameter?

The special thing is that the object acted upon by the method is passed as the first parameter of the function. In our example, a call to x.inquiry() is equivalent to Account.f(x). Generally, calling a method with n parameters is equivalent to inserting the method's action object into the first parameter position.

The above is the detailed content of Zhonggu Education Python video tutorial resource recommendation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Is the vscode extension malicious? Is the vscode extension malicious? Apr 15, 2025 pm 07:57 PM

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

How to run programs in terminal vscode How to run programs in terminal vscode Apr 15, 2025 pm 06:42 PM

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

Can visual studio code be used in python Can visual studio code be used in python Apr 15, 2025 pm 08:18 PM

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Can vscode run ipynb Can vscode run ipynb Apr 15, 2025 pm 07:30 PM

The key to running Jupyter Notebook in VS Code is to ensure that the Python environment is properly configured, understand that the code execution order is consistent with the cell order, and be aware of large files or external libraries that may affect performance. The code completion and debugging functions provided by VS Code can greatly improve coding efficiency and reduce errors.

See all articles