What language does Python look like its class syntax?

I want to start programming in python, and I was wondering which Python languages ​​resemble syntax? I am familiar with .net.

+3
source share
4 answers

No, really. Python syntax is unique.

ie (taken from: Python Tutorial - classes )

>>> class Complex:
...     def __init__(self, realpart, imagpart):
...         self.r = realpart
...         self.i = imagpart
...
>>> x = Complex(3.0, -4.5)
>>> x.r, x.i
(3.0, -4.5)

He was very inspired in ABC, but now it’s easier to learn Python than ABC.

See also: Python Wikipedia

+6
source

Python C, . , C, , Haskell, F #, ISWIM .

, Python, , - Modula-2 , , , .

+4

, , Python - Ruby, Ruby Python. , - .NET, IronPython IronRuby.

, Python , (, ) .

+1

. , indentaton . ,

def func():
    print "hello",
    print "world"

print . - ..

As for the classes, they are pretty much similar to what you expect - except that the pointer to the current object becomes explicit as the first argument to the function

class myclass:
    def classassign(self, string):
        self.mystr=string
    def classprint(self):
        print self.mystr

obj=myclass()
obj.classassign("class var")
obj.classprint()

prints

class var

Personally, Python is not very similar to any other languages ​​that I know, and that is a lot of fun. if this simple class is similar to what you are familiar with, you go. But I recommend a good Python book, since the “Pythonic” way of doing things is probably very different from what you expect

+1
source

Source: https://habr.com/ru/post/1779057/


All Articles