difference between () and [] in python

正在查看此主题的用户

this has been bugging the hell out of me for a while.. why are some functions enclosed in () and others in []?
sometimes a thing will work with one and screw up if i use the other, and other times it doesn't seem to matter at all which i use
look at this:
插入代码块:
  [trp_marnid,"member_separate_inn", [], "All right then. I'll meet you at the four ways inn. Good luck.", "close_window",
   [(store_conversation_troop,reg(0)),(remove_member_from_party,reg(0)),(add_troop_to_site, reg(0), "scn_four_ways_inn",marnid_inn_entry)]],
  [trp_borcha,"member_separate_inn", [], "I don't know what you will do without me, but you are the boss. I'll wait for you at the Four Ways inn.", "close_window",
   [[store_conversation_troop,reg(0)],[remove_member_from_party,reg(0)],[add_troop_to_site, reg(0), "scn_four_ways_inn", borcha_inn_entry]]],
this is straight from the native game.. marnid's bit uses () and borcha's uses [], and aside from that the code is identical and it does the exact same thing...
is there something obvious that i'm just not seeing? or does armagan just like to screw with my head?

maybe i'm a little OCD for this to bother me.. but it's driving me nuts... makes me want to kick a baby.. :evil:
 
They're the same for lists and tuples.
i.e. These are the same:

插入代码块:
[blah,blahblah,blah]
(blah,blahblah,blah)

But not for macro functions:
i.e. These are NOT the same, in fact the square brackets will cause an error.

插入代码块:
reg(10)
reg[10]
upgrade(troops,"bandit","brigand")
upgrade[troops,"bandit","brigand"]


Technically () and [ ] have different meanings in the Python language but for M&B modding, lists and tuples do the same thing, so they're interchangeable in some contexts.
 
() and [] have the same meaning. You just alternate them so you can tell the difference. This: ([([([()])])]) is a lot easier to keep track of than this: ((((((()))))))

They usually teach you this in 7th grade math.  :wink:
 
Logicians. Being married to one you know the violence that can be triggered by an incorrectly formated statement. Set theory is particularly dangerous.

Tip: Never tell a logician 'I love you.' because you won't receive the reaction you think. Instead try 'I love you, and only you.'
 
后退
顶部 底部