当前位置:网站首页>AiN 0722 签到
AiN 0722 签到
2022-07-24 05:15:00 【欣欣草木生】
0722签到
一. 下划线在Python的作用与意义
1 单下划线 _
如果会话中上一条语句执行的结果没有通过赋值语句赋值给一个变量,则该值默认赋值给 “_”
和计算器里的ans有点类似(如果没有赋值的话)
2 作为变量前的单下划线 “_”,如_name
变量所在模块/类以外的地方也能访问该变量,但最好不要(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
值得注意的是
以"_“”__"开头的名称都不会 from<>import∗ 这种形式导入
定义模块test1
'''模块test1.py'''
num = 20
_num = 40
__num = 60
__num__ = 80
from< test1 >import ∗
'''模块test2.py'''
from test1 import *
print(num) #20
print(_num) #报错,name '_num' is not defined
print(__num) #报错,name '__num' is not defined
print(__num__) #报错,name '__num__' is not defined
import test1
'''模块test2.py'''
import test1
print(test1.num) #输出20
print(test1._num) #输出40
print(test1.__num) #输出60
print(test1.__num__) #输出80
3 作为变量前的双下划线 “__”,如__name
变量所在模块/类以外的地方不能访问该变量,这是私有变量(private)
原因:
Python解释器对外把 __xxx变量改成了_classname__xxx
所以,仍然可以通过_classname__xxx来访问__xxx变量
class Student:
def __init__(self, name, age):
self.__name = name
self.age=age
stu = Student('Vicent',30)
print(stu.age) #输出30
print(stu._Student__name) #输出hello
print(stu.__name) #报错:AttributeError: 'Student' object has no attribute '__name'
4 变量前后的双下划线 如__ init __ ,__ name __
Python内置特殊变量,哪儿都可以访问
用户不以这样的命名形式自定义变量和函数时就不会和系统定义的方法冲突
一般是重写这些方法才会用到
例如,当定义一个类时,经常会覆写“init”方法。
class Student:
def __init__(self, name, age):
self.__name = name
self.age=age
除了 __ init __
还有__ del __ 、__ add __ 、__ getitem __ 等
以及全局的 __ file __ 、__ name __ 等。
二. conda的基本指令与操作
以下所有的环境的名称都以newd2l为例 , 读者请根据自己需要将newd2l替换成自己所需的环境名
以下所有的包的名字都以d2l为例 , 读者请根据自己需要将d2l替换成自己所需的包名
创建环境
conda create -n newd2l python=3.7
查看所有的环境
conda env list
切换环境
activate newd2l
删除环境
conda remove -n newd2l --all
检测包是否正常
pip check d2l
下载某个包
pip install d2l
卸载某个包
pip uninstall d2l
或者
conda remove --name newd2l d2l
提示 : 最好先uninstall再install实现更新某个包
查看包的版本号
conda list d2l
边栏推荐
- Reading excerpts from Liu run's "bottom logic"
- Theoretical basis of machine learning
- PXE efficient batch network installation
- Problems encountered in configuring Yum source
- Scikit learn -- steps of machine learning application development
- 酒店IPTV数字电视系统解决方案
- Jersey2.25.1集成freemarker
- MS simulated written test
- JMeter upload and download files
- 泛型和注解
猜你喜欢

Chapter5 foundation of deep learning

Performance test process

Image to image translation with conditional advantageous networks paper notes

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

OSS文件上传

反射的介绍

Basic knowledge of MySQL database
![Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]](/img/c1/320e0349e2edda0eb420ed018aa831.png)
Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]

frp内网穿透服务使用

XML schema
随机推荐
连接数%的准确率。现在拟需求。企业在数足以
Pointer learning diary (V) classic abstract data types and standard function libraries
2. Input a circle radius r, when r > = 0, calculate and output the area and perimeter of the circle, otherwise, output the prompt information.
1. There is a fractional sequence: 2/1, 3/2, 5/3, 8/5, 13/8,... Program to sum the first 20 items of this sequence.
View progress!!! RPM installation!!!
Globally and locally consistent image completion paper notes
Jetson设备 faild to download repository information使用小技巧记录
How to avoid the most common mistakes when building a knowledge base?
[advanced mathematics] the difference between differentiable and differentiable functions
[Basic 6] - encapsulation and inheritance of classes, objects and classes
Industry relevance of stock price trend
【Pytorch】conv2d torchvision.transforms
【Pytorch】nn.Module
Token of space renewable energy
IDEA:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.
泛型和注解
太空可再生能源的代币化
C table data De duplication
C primer plus learning notes - 6. Arrays and pointers
【sklearn】tree.DecisionTreeClassifier