Skip to main content
Post Undeleted by ofir1080
Post Deleted by ofir1080
deleted 6 characters in body
Source Link
ofir1080
  • 145
  • 1
  • 7

Given the following trivial function:

def func(x):
     return x if True else x, x

Why is type(func(1)) returns the tuple (1, 1), even if the desired results would be the identity?

However, note that the following:

def func(x):
    return x if True else (x, x)

Does return the desired integer type. Can anyone explain such behavior and why this happens?

Given the following trivial function:

def func(x):
     return x if True else x, x

Why is type(func(1)) returns the tuple (1, 1), even if the desired results would be the identity?

However, note that the following:

def func(x):
    return x if True else (x, x)

Does return the desired integer type. Can anyone explain such behavior and why this happens?

Given the following trivial function:

def func(x):
     return x if True else x, x

Why is func(1) returns the tuple (1, 1), even if the desired results would be the identity?

However, note that the following:

def func(x):
    return x if True else (x, x)

Does return the desired integer type. Can anyone explain such behavior and why this happens?

Source Link
ofir1080
  • 145
  • 1
  • 7

One-line if-else in Python: interpreting behavior

Given the following trivial function:

def func(x):
     return x if True else x, x

Why is type(func(1)) returns the tuple (1, 1), even if the desired results would be the identity?

However, note that the following:

def func(x):
    return x if True else (x, x)

Does return the desired integer type. Can anyone explain such behavior and why this happens?