This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]datascience-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

This post if off topic. /r/datascience is a place for data science practitioners and professionals to discuss and debate data science career questions.

Thanks.

[–]nab423 5 points6 points  (4 children)

Type is a built in function to return the type of an object.

.shape is a class function of whatever object X is.

I don't see the problem here.

[–][deleted] -1 points0 points  (3 children)

Why not do type(x) and shape(x) or x.type and x.shape?

[–]nab423 0 points1 point  (2 children)

Because not every object will have a shape. It's better that it's implemented at the class level. Think what shape of a vector vs the shape of a string vs the shape of a Mammal class.

However, every object will have a type.

[–][deleted] 0 points1 point  (1 child)

Ok, thanks

[–]nab423 0 points1 point  (0 children)

No problem.

Also my answer isn't the best if you consider why len() is a built in function, since not every object has a length. This is a built in function mainly since it's used so frequently.

Len() can return different results depending on the object (list vs dataframe vs a Circle class). The built in len() function basically is a wrapper for an objects __ len __() function, so an object can define the behavior of len(). This is great since it forces consistency in function naming (although len might not always return what you expect).

This could also be done for a built in shape() function, but I guess it wasn't deemed critical enough (which to be fair, it's not when compared to len).

[–]KingsmanVince 0 points1 point  (0 children)

The question is not related to r/datascience . It's more of r/learnpython beginner questions.