Is there a built-in method for transforming (1,None,"Hello!") to 1,None,"Hello!"?

D

Daniel Crespo

Is there a built-in method for transforming (1,None,"Hello!") to
1,None,"Hello!"?

Thanks
 
B

bonono

do you mean this ? otherwise, don't know what you want.

a, b, c = (1, None, "Hello!")
 
S

Simon Brunning

Is there a built-in method for transforming (1,None,"Hello!") to
1,None,"Hello!"?

There's no conversion to do:
(1, None, 'Hello!')

They are both tuples contining identicle elements. What is it that you
want to do?
 
A

Alex Martelli

Daniel Crespo said:
Is there a built-in method for transforming (1,None,"Hello!") to
1,None,"Hello!"?

You're mentioning two different literal syntaxes for the same object (a
tuple) -- the one with parentheses works everywhere, the other one
_almost_ everywhere (not where parentheses would be ambiguous).

Not sure, therefore, what you mean by "transforming" here; if you're
dealing with a string for in either case, for example, you could remove
the first and last characters by slicing with [1:-1], etc, etc. Perhaps
you can clarify exactly what you're asking for!


Alex
 
A

Amaury

Hello,

Daniel said:
Is there a built-in method for transforming (1,None,"Hello!") to
1,None,"Hello!"?

As others answered before, the two syntaxes build the same object, so
there is no need to convert.

Except if you already have the tuple stored in a variable, and want to
call a function with the tree arguments:
args = (1,None,"Hello!")

func(args) # equivalent to func((1,None,"Hello!"))
func(*args) # equivalent to func(1,None,"Hello!")

Note the '*' on the second call, it will flatten the args, and 3
arguments are passed to the function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hello!! 0
Hello! 2
Hello All! 0
Hello to community. 3
Hello everyone 0
Hello Everyone! 1
Hello everyone! 0
Hello there ! 2

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top