当前位置:网站首页>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
边栏推荐
- )To feed back to the application layer or into multiple format documents:
- Blue Bridge Cup 31 day sprint 21 day (C language)
- The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands
- Using a* heuristic search to solve maze routing problem
- Markov random field: definition, properties, maximum a posteriori probability problem, energy minimization problem
- Hanoi problem
- Chapter5 foundation of deep learning
- Execution sequence of finally and return
- Pointer learning diary (IV) use structure and pointer (linked list)
- 线程的介绍
猜你喜欢

Drools development decision table

PPPoE网关模拟环境搭建

Machine vision learning summary

c2-随机产生函数种子seed、numpy.random.seed()、tf.random.set_seed学习+转载整理
![[database connection] - excerpt from training](/img/7d/334b4b7f0f6e1de228c4ecb1e600a3.png)
[database connection] - excerpt from training

Update C language notes

scikit-learn笔记

Beginners' preparation for the Blue Bridge Cup (University Programming learning history records, topic ideas for students who need to prepare for the Blue Bridge Cup)

PXE efficient batch network installation

postgresql:在Docker中运行PostgreSQL + pgAdmin 4
随机推荐
Sword finger offer special assault edition day 7
JMeter FAQs
C primer plus learning notes - 6. Arrays and pointers
Context encoders: feature learning by painting paper notes
In his early 30s, he became a doctoral director of Fudan University. Chen Siming: I want to write both codes and poems
The world's first large aerospace model came out. Wenxin's second supplement "Fuchun Mountain Residence map" is Baidu Pratt Whitney AI's perseverance
The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands
Pointer learning diary (I)
What are the core strengths of a knowledge base that supports customers quickly?
Machine vision learning summary
FTP file transfer protocol
Echo speaker pairing and operation method
Using a* heuristic search to solve maze routing problem
DNS domain name resolution service
Mrs +apache Zeppelin makes data analysis more convenient
Drools development decision table
泛型和注解
JSP+Dao整合
[deep learning] (III) image classification
C primer plus learning notes - 5. Pointer