这些Java概念如何转化为Python? [英] How do these Java concepts translate to Python?

查看:74
本文介绍了这些Java概念如何转化为Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我在业余时间学习过Python。我是一名Java / C ++程序员,通过

交易。所以我一直在阅读Python OO,我有几个问题

我找不到答案:)


1 。访问说明符在哪里? (公共,受保护,私人)

2. Python如何知道课程是新风格还是旧风格?

例如:


A级:

通过


如何知道课程是新风格还是旧风格?或者这个

决定只发生在我添加属于新的

风格的东西时?我如何告诉Python我想使用哪一个?


3.在Java中我们有静态(类)方法和实例成员。但是,这个

差异似乎在Python中变得模糊。我的意思是,当你在Python中绑定一个成员

变量时,它是静态的还是实例?在Python中,似乎所有内容都是静态的(在Java意义上)。我是否正确?


提前致谢,

Ray

Hello,

I''ve been learning Python in my sparetime. I''m a Java/C++ programmer by
trade. So I''ve been reading about Python OO, and I have a few questions
that I haven''t found the answers for :)

1. Where are the access specifiers? (public, protected, private)
2. How does Python know whether a class is new style or old style?
E.g.:

class A:
pass

How does it know whether the class is new style or old style? Or this
decision only happens when I''ve added something that belongs to new
style? How do I tell Python which one I want to use?

3. In Java we have static (class) method and instance members. But this
difference seems to blur in Python. I mean, when you bind a member
variable in Python, is it static, or instance? It seems that everything
is static (in the Java sense) in Python. Am I correct?

Thanks in advance,
Ray

推荐答案



Ray写道:

Ray wrote:
1.访问说明符在哪里? (公共,受保护,私人)
1. Where are the access specifiers? (public, protected, private)




AFAIK,Python中没有这样的东西。


--- Fausto



AFAIK, there is not such a thing in Python.

---Fausto




Fausto Arinos Barbuto写道:

Fausto Arinos Barbuto wrote:
Ray写道:
Ray wrote:
1.访问说明符在哪里? (公共,受保护,私有)
1. Where are the access specifiers? (public, protected, private)



AFAIK,Python中没有这样的东西。

--- Fausto



AFAIK, there is not such a thing in Python.

---Fausto




嗯,从技术上讲,你可以使用_attribute来破坏它,但从技术上说,b
,没有公共,受保护或隐私的东西。



Well, technically you can use _attribute to mangle it, but technically
speaking, there are no public, protected, or private things.


Fausto Arinos Barbuto写道:
Fausto Arinos Barbuto wrote:
Ray写道:
Ray wrote:
1.访问说明符在哪里? (公共,受保护,私有)
AFAIK,Python中没有这样的东西。
1. Where are the access specifiers? (public, protected, private)
AFAIK, there is not such a thing in Python.




所以一切都是公开的?我知道你可以给一个成员加上

下划线作为私有内容的前缀,但是如何保护,对于

例子?

--- Fausto



So everything is public? I know that you can prefix a member with
underscores to make something private, but how about protected, for
example?

---Fausto






这篇关于这些Java概念如何转化为Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆