1

There is operator overloading in Python. In the official documentation there is a list of operators.

However in the Pandas documentation, [] and ., which are not present in list of operators in the previous link, are also called operators.

Note The Python and NumPy indexing operators [] and attribute operator . provide quick and easy access to pandas data structures across a wide range of use cases.

Are [] and . operators in Python? Can they be, and are they overloaded in Pandas?

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
Child Detektiv
  • 237
  • 1
  • 12
  • 1
    bit of info here...my personal opinion is to just always use [] https://stackoverflow.com/questions/41130255/for-pandas-dataframe-whats-the-difference-between-using-squared-brackets-or-do – Derek Eden Sep 05 '19 at 13:34
  • 4
    Why are you looking at docs for Python **2.0**? :o We're at 2.7 and 3.7. You're looking at 18-year-old stuff! `June 22, 2001 Release 2.0.1` How did you even find it? – h4z3 Sep 05 '19 at 13:35
  • 1
    `__getitem__`, `__setitem__`, and if you need it: `__delitem__` https://docs.python.org/3/library/operator.html – h4z3 Sep 05 '19 at 13:46
  • @h4z3 in asnwer by "Cong Ma" in https://stackoverflow.com/questions/43627405/understanding-getitem-method "The [] syntax for getting item by key or index is just syntax sugar." Do you agree or not? – Alex Martian Sep 05 '19 at 13:54
  • @h4z3, in the link both get and set are for []. What about dot? – Child Detektiv Sep 05 '19 at 14:01
  • @h4z3 good catch! I have amended my edit, it was only visual, I've updated the link as well, after checking in 3 version I could not see [] either. – Alex Martian Sep 05 '19 at 14:27

1 Answers1

1

Both [] and . (dot) are in next section of user docs: 2.6. Delimiters

https://docs.python.org/3/reference/lexical_analysis.html#delimiters

AFAIK these are not formally operators and cannot be overloaded. As for their actual use in pandas you are welcome to see for yourself in the link you youself posted:
https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html.

Alex Martian
  • 3,423
  • 7
  • 36
  • 71