What is Python’s First-Class?

Asked

Viewed 126 times

2

The first-class Java language are objects, as nothing can be created in Java without the use of classes. In Haskell, following the same previous criterion, the first-class are functions. In the case of Python, what is considered the first-class of the language?

  • 4

    Anything can be first class, nothing needs to be, so wanting to choose one makes no sense. This idea that objects are first-class in Java is false. https://answall.com/q/227485/101 Indeed even the idea that everything depends on class, that everything is object-oriented is true.

1 answer

-4

Everything in python is a first-class, as everything is Object and Object is first-class. That is, a class, a function, a method... are assignable, referential, and so on, using the standard data structure of the language. In java, that’s not true. Follows a demonstration:

Python:

class A:
  pass

def test():
  pass

print(isinstance(test,object))
a = 1
print(isinstance(a,object))
a = A()
print(isinstance(a,object))
print(isinstance(A,object))

Java:

public class Test {

    public static void main(String... args){
        int a = 1;
        System.out.println( a instanceof Object);
    }
}

Ref: https://docs.python.org/3/reference/datamodel.html

But in java it is possible to say that primitive objects and types are first-class.

Ref: https://en.wikipedia.org/wiki/First-class_citizen

Browser other questions tagged

You are not signed in. Login or sign up in order to post.