Right, I meant tuple, not list.
a = ('A string')
b = ('A List Member',)
print(a[0])
print(b[0])
The output for this is:
A
A List Member
@mike
-----Original Message-----
From: Cameron Simpson <[email protected]>
Sent: Friday, July 12, 2019 7:59 PM
To: Mike Barnett <[email protected]>
Cc: Shall, Sydney <[email protected]>; [email protected]
Subject: Re: [Tutor] Multiprocessing with many input input parameters
On 11Jul2019 15:40, Mike Barnett <[email protected]> wrote:
>If you're passing parameters as a list, then you need a "," at the end of the
>items. Otherwise if you have something like a string as the only item, the
>list will be the string.
>
>list_with_one_item = ['item one',]
Actually, this isn't true.
This is a one element list, no trailing coma required:
[5]
Mike has probably confused this with tuples. Because tuples are delineated with
parentheses, there is ambiguity between a tuple's parentheses and normal "group
these terms together" parentheses.
So:
x = 5 + 4 * (9 + 7)
Here we just have parentheses causing the assignment "9 + 7" to occur before
the multiplication by 4. And this is also legal:
x = 5 + 4 * (9)
where the parentheses don't add anything special in terma of behaviour.
Here is a 2 element tuple:
(9, 7)
How does one write a one element tuple? Like this:
(9,)
Here the trailing comma is _required_ to syntacticly indicate that we intend a
1 element tuple instead of a plain "9 in parentheses") as in the earlier
assignment statement.
I'm not sure any of this is relevant to Sydney's question though.
Cheers,
Cameron Simpson <[email protected]>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor