当前位置:网站首页>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
边栏推荐
- Zhaoyi innovation gd25wdxxk6 SPI nor flash product series comes out
- Accuracy of% connections. Now it is planned to meet the demand. The number of enterprises is enough
- 1、基于增量式生成遮挡与对抗抑制的行人再识别
- jdbc的增删改查
- Blue Bridge Cup 31 day sprint 21 day (C language)
- postgresql:在Docker中运行PostgreSQL + pgAdmin 4
- Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]
- frp内网穿透服务使用
- Jetson设备 faild to download repository information使用小技巧记录
- un7.23:如何在linix上安装MySQL?
猜你喜欢

IDEA:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.

DHCP principle and configuration

PXE efficient batch network installation

线程的介绍

SSH service

How to avoid the most common mistakes when building a knowledge base?

jdbc封装一个父类减少代码重复

利用a*启发式搜索解决迷宫寻路问题
![Embedded system transplantation [3] - uboot burning and use](/img/36/69daec5f1fe41bd3d0433d60816bba.png)
Embedded system transplantation [3] - uboot burning and use

Using a* heuristic search to solve maze routing problem
随机推荐
PostgreSQL: run PostgreSQL + pgadmin 4 in docker
What are the core strengths of a knowledge base that supports customers quickly?
MySQL深入了解
泛型和注解
Execution sequence of finally and return
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)
Pointer learning diary (IV) use structure and pointer (linked list)
Markov random field: definition, properties, maximum a posteriori probability problem, energy minimization problem
)To feed back to the application layer or into multiple format documents:
Machine vision learning summary
Bear market bottoming Guide
Binary SCA fingerprint extraction black Technology: go language Reverse Technology
Reading excerpts from Liu run's "bottom logic"
JMeter FAQs
NLP learning roadmap (mind map) is very comprehensive and clear!
FRP intranet penetration service usage
Installation and login login
反射
【【【递归】】】
[database connection] - excerpt from training