Open up iPython and type this:
/
Hit enter and wonder about the result:
()
You cannot assign it, my guess it has something to do with the shell functionality.
Edit:
You can assign it with:
p = Out[xx]
But not directly:
p = /
will give:
SyntaxError
It is indeed an empty tuple.
There are two ways to initialize an empty tuple. You can initialize an empty tuple by having () with no values in them. You can also initialize an empty tuple by using the tuple function. A tuple with values can be initialized by making a sequence of values separated by commas.
You can create empty tuple object by giving no elements in parentheses in assignment statement. Empty tuple object is also created by tuple() built-in function without any arguments >>> T1 = () >>> T1 () >>> T1 = tuple() >>> T1 () Pythonic. © Copyright 2022.
Tuples represent arbitrary sequences of values. When you need to describe an empty sequence of values, you can use an empty tuple.
In python, an empty tuple always evaluates to false.
It is a convenience feature for callable objects/names. It's not an empty tuple, but parentheses completion. From iPython's help system (?
):
Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
Auto-parentheses
Callable objects (i.e. functions, methods, etc) can be invoked like this (notice the commas between the arguments)::
In [1]: callable_ob arg1, arg2, arg3
and the input will be translated to this::
callable_ob(arg1, arg2, arg3)
This feature is off by default (in rare cases it can produce undesirable side-effects), but you can activate it at the command-line by starting IPython with
--autocall 1
, set it permanently in your configuration file, or turn on at runtime with%autocall 1
.You can force auto-parentheses by using '/' as the first character of a line. For example::
In [1]: /globals # becomes 'globals()'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With