当前位置:网站首页>Ain 0722 sign in
Ain 0722 sign in
2022-07-24 05:26:00 【Xinxin vegetation】
0722 Sign in
One . Underline in Python Function and significance of
1 Underline _
If the result of the last statement in the session is not assigned to a variable through the assignment statement , Then the value is assigned to “_”
And the calculator ans It's kind of similar ( If there is no assignment )
2 As a single underscore before variables “_”, Such as _name
The module where the variable is located / The variable can also be accessed outside the class , But better not (protected)
class Student:
def __init__(self, name, age):
self._name = name
self.age=age
stu = Student('hello',30)
print(stu.age) #30
print(stu._name) #hello
It is worth noting that
With "_“”__" The beginning of the name will not from<>import∗ Import in this form
Define modules test1
''' modular test1.py'''
num = 20
_num = 40
__num = 60
__num__ = 80
from< test1 >import ∗
''' modular test2.py'''
from test1 import *
print(num) #20
print(_num) # Report errors ,name '_num' is not defined
print(__num) # Report errors ,name '__num' is not defined
print(__num__) # Report errors ,name '__num__' is not defined
import test1
''' modular test2.py'''
import test1
print(test1.num) # Output 20
print(test1._num) # Output 40
print(test1.__num) # Output 60
print(test1.__num__) # Output 80
3 As double underscores before variables “__”, Such as __name
The module where the variable is located / The variable cannot be accessed outside the class , This is a private variable (private)
reason :
Python The interpreter puts out __xxx Variable changed to _classname__xxx
therefore , Can still pass _classname__xxx To visit __xxx Variable
class Student:
def __init__(self, name, age):
self.__name = name
self.age=age
stu = Student('Vicent',30)
print(stu.age) # Output 30
print(stu._Student__name) # Output hello
print(stu.__name) # Report errors :AttributeError: 'Student' object has no attribute '__name'
4 Double underscores before and after variables Such as __ init __ ,__ name __
Python Built in special variables , You can visit anywhere
If users do not customize variables and functions in this naming form, they will not conflict with the methods defined by the system
Generally, it is only by rewriting these methods that we can use
for example , When defining a class , I often override “init” Method .
class Student:
def __init__(self, name, age):
self.__name = name
self.age=age
except __ init __
also __ del __ 、__ add __ 、__ getitem __ etc.
And the overall situation __ file __ 、__ name __ etc. .
Two . conda Basic instructions and operations
All of the following The name of the environment is newd2l For example , Readers should send newd2l Replace with the desired environment name
All of the following The name of the package is d2l For example , Readers should send d2l Replace with the package name you need
Create an environment
conda create -n newd2l python=3.7
Look at all the environments
conda env list
Switching environment
activate newd2l
Delete environment
conda remove -n newd2l --all
Check whether the package is normal
pip check d2l
Download a package
pip install d2l
Unload a package
pip uninstall d2l
perhaps
conda remove --name newd2l d2l
Tips : Better first uninstall Again install Update a package
Check the version number of the package
conda list d2l
边栏推荐
- web开发
- T 6-10
- 这是第一篇
- Basic knowledge of MySQL database
- Bear market bottoming Guide
- )To feed back to the application layer or into multiple format documents:
- Skills of BeanShell dealing with JSON
- Jersey2.25.1集成freemarker
- The difference between compiled language and interpreted language
- I'm interested in reading efficient reading - the most cost-effective self investment
猜你喜欢

MySQL insight

JDBC encapsulates a parent class to reduce code duplication

Machine vision learning summary
![[database connection] - excerpt from training](/img/7d/334b4b7f0f6e1de228c4ecb1e600a3.png)
[database connection] - excerpt from training

1、基于增量式生成遮挡与对抗抑制的行人再识别

What are the core strengths of a knowledge base that supports customers quickly?

【sklearn】PCA

反射的介绍

Basic knowledge of MySQL database

【Pytorch】conv2d torchvision.transforms
随机推荐
C语言入门篇 二.函数
谈谈对未来的想法
递归还能这么玩?递归实现扫雷游戏
Data annotation learning summary
A collation of the basic usage of numpy
【【【递归】】】
generator生成器,只生成两个方法
一步一步带你学C(其一)
MySQL insight
MySQL深入了解
MQTT学习
C语言进阶篇 六.文件的操作
anaconda常用命令的整理
Detailed explanation of string constant pool and intern() of string
Knowledge record of College Physics C in advance in summer [update]
Tips for using the built-in variable props of BeanShell
【Pytorch】conv2d torchvision.transforms
Numpy statistical correlation function example tutorial
Add, delete, modify and check JDBC
九大排序实现与比较(万字总结)