Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference () and []
#1
I need to know whats the difference in:
something()
and
something[]
Reply
#2
something() applies to objects having a __call__() method and it executes this method, while something[] applies to objects having a __getitem__() method and it executes this method.
Reply
#3
Examples of the two cases mentioned by Gribouillis are functions in the former case and lists/dictionaries/tuples in the latter.
Reply
#4
Also consider braces {}. A good source to see what you use when is the docs at Python Docs
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020