d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Python Q
Add Reply New Topic New Poll
Member
Posts: 21,174
Joined: Feb 28 2010
Gold: 300.00
Jun 5 2020 11:03am
When I'm appending lists is there a reason why a single string/number value only uses single brackets e.g. --> append(string/value) and a double string/integer value uses e.g --> .append(('string', #))

I was under the impression only 'one' item at a time can be used with append, however I encountered a few times where that was not that case. That said I only encountered it when I had a string and integer append being made, not both of the same.


That said does it add double brackets because it is combining a string with an integer in a list?

If, we had a variable and did an append w/ say two strings (or) two integers, would the same (( value, value)) apply or can we simply use (value, value). My guess is it would not work, as I mentioned in line two above.


Thanks for your time,

Frozen

This post was edited by FroZen420 on Jun 5 2020 11:15am
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Jun 5 2020 10:57pm
(x, y) is tuple syntax, which is just a collection of items. A tuple can be any size, but its size cannot be modified. If you want to add another element to it, you have to create a new tuple with 3 elements (in this case (x, y, z))
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll