![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Use Python
Learn Python by using it.
ShaneRun
To Think, To Explore, To Contribute.
展开
-
“_“, “__“ and “__xxx__“ in Python?
ItemUsageDescriptionNotes_attribute保护变量类实例和子类实例能访问到这些变量需通过类提供的接口进行访问;不能用’from module import *'导入__attribute私有变量类对象自己能访问__func__系统定义代表python里特殊方法专用的标识如 __init__()代表类的构造函数默认情况下,Python中的成员函数和成员变量都是公开的(public),在python中没有类public,p...原创 2020-12-08 16:12:12 · 73 阅读 · 0 评论 -
how to understand “super(classname, self).__init__()“ in Python?
# python中的super(Net, self).__init__()# 首先找到Net的父类(比如是类NNet),# 然后把类Net的对象self转换为类NNet的对象,# 然后“被转换”的类NNet对象调用自己的init函数, # see <https://blog.csdn.net/wltsysterm/article/details/104440387>super(classname, self).__init__() # required in Python2In P原创 2020-12-08 16:04:49 · 97 阅读 · 0 评论 -
Python: *args, **kwargs, **vars(args)?
variablesfunctionnotes*args*args(1) 表示任何多个无名参数,它本质是一个 tuple告诉函数,按tuple来解析args**kwargs**kwargs(1) 表示任何多个关键字参数,它本质上是一个 dict告诉函数,按dict来解析args,如果同时使用 *args 和 **kwargs 时,必须 *args 参数列要在 **kwargs 之前**vars(args)这与 **kwargs是类似的,告诉函数按dict来解析,还多...原创 2020-12-08 13:23:43 · 2311 阅读 · 0 评论 -
understand “*“ and “**“ in Python
No.categorydescriptionnotes1operator* is multiply, ** is square算数运算, *代表乘法, **代表乘方2formal argumentunknown numbers of arguments, * for decoding as tuple, ** for decoding as dict函数形参,*args 和 **kwargs 主要用于函数定义, 实现将不定数量的参数传递给一个函数3actua...原创 2020-12-08 12:47:09 · 86 阅读 · 0 评论 -
Python if __name__ == ‘__main__‘
(1) “__name__” 是内置变量,用于表示当前模块的名字,同时还能反映一个包的结构。(2)如果一个模块被直接运行,则其没有包结构,其 “__name__ ”值为“ __main__”.理解1:简单理解如果模块是被直接运行的,则代码块被运行,如果模块是被导入(import)的,则代码块不被运行。理解2:模拟的程序入口对于很多编程语言来说,程序都必须要有一个入口,比如 C,C++,都需要有一个main 函数来作为程序的入口。Python 则不同,它属于脚本语言,不像编译型语言那样先将程原创 2020-12-08 10:08:12 · 118 阅读 · 0 评论 -
[201117] 为什么range范围是左闭右开区间?
[201117] 为什么range范围是左闭右开区间?range(i,j) 相当于 [i,j)这实际上遵守的是不对称边界的设计思想,是一种编程技巧,其根本原因是为了解决程序设计中难于察觉的“栏杆错误”,也叫“差一错误”(off-by-one error)(参见《C陷阱与缺陷》,p46)。Python的数组下标是从0开始的,这一点和C语言是相同的。不对称边界的编程技巧,有两种表示方式:用第一个入界点和第一个出界点来表示一个数值范围。用第一个被占用的元素和第一个被释放的元素分别来表示上界和下界。原创 2020-11-17 14:41:49 · 1672 阅读 · 0 评论 -
[python_tsk_00] Install numpy and scipy in Win10 via pip3
ID = python_tsk_00TaskStatus: Got this error ModuleNotFoundError: No module named 'numpy'Task: To install numpy and scipy in Win10.ActionUse pip3 to make it, and referenced to this linkThis is the step-by-step operation record:Step1: Install and che原创 2020-09-15 16:45:13 · 141 阅读 · 0 评论 -
[200809] return more than 1 value in python and C
[200809] return more than 1 value in python and CIn python, it is very easy, and the return value is assembled as tuple format:def fun(a,b): # 返回多个值,结果以元组形式表示 return a,b,a+bprint(fun(1,2))# Result(1, 2, 3)In C, normally, it can have onl原创 2020-08-09 15:01:22 · 71 阅读 · 0 评论 -
python_ask_00-How to understand *self*?
ID = python_ask_00ContentQuestionAnswerExample 1Example 2ReferenceQuestionHow to understand self?AnswerTo define a method inside class, need to contain self as the first arguments.self is instance of the class, which represents address of current ob原创 2020-07-14 06:34:34 · 92 阅读 · 0 评论 -
python_ask_02-Are object and instance the same?
ID = python_ask_02文章目录QuestionAnswerReferenceQuestionAre object and instance the same?AnswerAre they the same?My answer is NO.We say everything is object, but we never say everything is instance.Class and instance are both object.「对象」是一个有行为的东西。「原创 2020-07-01 22:19:53 · 103 阅读 · 0 评论 -
python_ask_01-How to undertand everything in python is object?
ID = python_ask_01文章目录QuestionAnswerReferenceQuestionHow to understand everything in Python is object?AnswerClass is abstracted object, Instance is specific object, they are both object.Even number is also an object, it is instance of class int?The原创 2020-07-01 22:18:39 · 101 阅读 · 0 评论 -
python_std_00-Similarities and Differences bwtween C and Python
ID = python_std_00文章目录TopicStudy recordReferenceTopicSimilarities and Differences bwtween C and PythonStudy record分类CPython3说明引用includeimportPython可以用 from import 引用某些函数,C不能代码块{}‘:’+ 缩进最大区别Python 的代码块用相同数目的行首缩进空格数来控制单行注释//#原创 2020-06-24 11:34:06 · 118 阅读 · 0 评论