del() vs del statement in python [duplicate]
This question already has an answer here:
Why does del (x) with parentheses around the variable name work?
1 answer
python assert with and without parenthesis
5 answers
>>> li = [1, 2, 3, 4]
>>> li
[1, 2, 3, 4]
>>> del li[2] #case 1
>>> li
[1, 2, 4]
>>> del(li[2]) # case 2
>>> li
[1, 2]
>>> del (li[1]) # case 3
>>> li
[1]
>>>
One of my professors used case 2 to delete item from list.
As per python documentation case 1 is right and there is also another syntactic way exist from this answer so case 3 also right, but as per my knowledge there is no del method exist in python, how case 2 is valid. I searched whole python documentation but could not find it.
Update:
if i write del method myself in my module and use case 2 at same time, how python interpreter differentiates between them or will it through an error, although i never tried until now
python python-3.x
marked as duplicate by Chris_Rands
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 9 more comments
This question already has an answer here:
Why does del (x) with parentheses around the variable name work?
1 answer
python assert with and without parenthesis
5 answers
>>> li = [1, 2, 3, 4]
>>> li
[1, 2, 3, 4]
>>> del li[2] #case 1
>>> li
[1, 2, 4]
>>> del(li[2]) # case 2
>>> li
[1, 2]
>>> del (li[1]) # case 3
>>> li
[1]
>>>
One of my professors used case 2 to delete item from list.
As per python documentation case 1 is right and there is also another syntactic way exist from this answer so case 3 also right, but as per my knowledge there is no del method exist in python, how case 2 is valid. I searched whole python documentation but could not find it.
Update:
if i write del method myself in my module and use case 2 at same time, how python interpreter differentiates between them or will it through an error, although i never tried until now
python python-3.x
marked as duplicate by Chris_Rands
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
5
You can put parentheses in lots of places without affecting anything. Here they're simply redundant. Just likereturn 1
is the same asreturn (1)
.
– khelwood
Nov 15 '18 at 15:32
okay, if i write del method in my module and use the above at same time, how python interpreter differentiates between the, although i never tried until now.
– Srinivas
Nov 15 '18 at 15:34
3
Case 2 is not a function call, it is still a statement call. The same reason whyif(cond)
andif (cond)
andif cond
are all the same.
– Gerges
Nov 15 '18 at 15:34
You should stick withdel ((((((((((((((((((((( list[0] )))))))))))))))))))))
;)
– Chris_Rands
Nov 15 '18 at 15:35
2
You can't write adel
function in your module.del
is a keyword.
– khelwood
Nov 15 '18 at 15:37
|
show 9 more comments
This question already has an answer here:
Why does del (x) with parentheses around the variable name work?
1 answer
python assert with and without parenthesis
5 answers
>>> li = [1, 2, 3, 4]
>>> li
[1, 2, 3, 4]
>>> del li[2] #case 1
>>> li
[1, 2, 4]
>>> del(li[2]) # case 2
>>> li
[1, 2]
>>> del (li[1]) # case 3
>>> li
[1]
>>>
One of my professors used case 2 to delete item from list.
As per python documentation case 1 is right and there is also another syntactic way exist from this answer so case 3 also right, but as per my knowledge there is no del method exist in python, how case 2 is valid. I searched whole python documentation but could not find it.
Update:
if i write del method myself in my module and use case 2 at same time, how python interpreter differentiates between them or will it through an error, although i never tried until now
python python-3.x
This question already has an answer here:
Why does del (x) with parentheses around the variable name work?
1 answer
python assert with and without parenthesis
5 answers
>>> li = [1, 2, 3, 4]
>>> li
[1, 2, 3, 4]
>>> del li[2] #case 1
>>> li
[1, 2, 4]
>>> del(li[2]) # case 2
>>> li
[1, 2]
>>> del (li[1]) # case 3
>>> li
[1]
>>>
One of my professors used case 2 to delete item from list.
As per python documentation case 1 is right and there is also another syntactic way exist from this answer so case 3 also right, but as per my knowledge there is no del method exist in python, how case 2 is valid. I searched whole python documentation but could not find it.
Update:
if i write del method myself in my module and use case 2 at same time, how python interpreter differentiates between them or will it through an error, although i never tried until now
This question already has an answer here:
Why does del (x) with parentheses around the variable name work?
1 answer
python assert with and without parenthesis
5 answers
python python-3.x
python python-3.x
edited Nov 15 '18 at 15:50
dawg
59.9k1285154
59.9k1285154
asked Nov 15 '18 at 15:29
SrinivasSrinivas
1299
1299
marked as duplicate by Chris_Rands
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Chris_Rands
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 15 '18 at 15:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
5
You can put parentheses in lots of places without affecting anything. Here they're simply redundant. Just likereturn 1
is the same asreturn (1)
.
– khelwood
Nov 15 '18 at 15:32
okay, if i write del method in my module and use the above at same time, how python interpreter differentiates between the, although i never tried until now.
– Srinivas
Nov 15 '18 at 15:34
3
Case 2 is not a function call, it is still a statement call. The same reason whyif(cond)
andif (cond)
andif cond
are all the same.
– Gerges
Nov 15 '18 at 15:34
You should stick withdel ((((((((((((((((((((( list[0] )))))))))))))))))))))
;)
– Chris_Rands
Nov 15 '18 at 15:35
2
You can't write adel
function in your module.del
is a keyword.
– khelwood
Nov 15 '18 at 15:37
|
show 9 more comments
5
You can put parentheses in lots of places without affecting anything. Here they're simply redundant. Just likereturn 1
is the same asreturn (1)
.
– khelwood
Nov 15 '18 at 15:32
okay, if i write del method in my module and use the above at same time, how python interpreter differentiates between the, although i never tried until now.
– Srinivas
Nov 15 '18 at 15:34
3
Case 2 is not a function call, it is still a statement call. The same reason whyif(cond)
andif (cond)
andif cond
are all the same.
– Gerges
Nov 15 '18 at 15:34
You should stick withdel ((((((((((((((((((((( list[0] )))))))))))))))))))))
;)
– Chris_Rands
Nov 15 '18 at 15:35
2
You can't write adel
function in your module.del
is a keyword.
– khelwood
Nov 15 '18 at 15:37
5
5
You can put parentheses in lots of places without affecting anything. Here they're simply redundant. Just like
return 1
is the same as return (1)
.– khelwood
Nov 15 '18 at 15:32
You can put parentheses in lots of places without affecting anything. Here they're simply redundant. Just like
return 1
is the same as return (1)
.– khelwood
Nov 15 '18 at 15:32
okay, if i write del method in my module and use the above at same time, how python interpreter differentiates between the, although i never tried until now.
– Srinivas
Nov 15 '18 at 15:34
okay, if i write del method in my module and use the above at same time, how python interpreter differentiates between the, although i never tried until now.
– Srinivas
Nov 15 '18 at 15:34
3
3
Case 2 is not a function call, it is still a statement call. The same reason why
if(cond)
and if (cond)
and if cond
are all the same.– Gerges
Nov 15 '18 at 15:34
Case 2 is not a function call, it is still a statement call. The same reason why
if(cond)
and if (cond)
and if cond
are all the same.– Gerges
Nov 15 '18 at 15:34
You should stick with
del ((((((((((((((((((((( list[0] )))))))))))))))))))))
;)– Chris_Rands
Nov 15 '18 at 15:35
You should stick with
del ((((((((((((((((((((( list[0] )))))))))))))))))))))
;)– Chris_Rands
Nov 15 '18 at 15:35
2
2
You can't write a
del
function in your module. del
is a keyword.– khelwood
Nov 15 '18 at 15:37
You can't write a
del
function in your module. del
is a keyword.– khelwood
Nov 15 '18 at 15:37
|
show 9 more comments
2 Answers
2
active
oldest
votes
All of them are the same, del
is a keyword as yield
or return
, and (list[1])
evaluates to list[1]
. So del(list[1])
and del (list[1])
are the same. For the base case, since you dont have the ()
you need to force the extra space, hence del list[1]
.
EDIT: You cannot redifine del
since it is a language keyword.
add a comment |
The parenthehis is not mandatory with keyword (like if
or del
), but can put some if you want.
it's exactly the same thing
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
All of them are the same, del
is a keyword as yield
or return
, and (list[1])
evaluates to list[1]
. So del(list[1])
and del (list[1])
are the same. For the base case, since you dont have the ()
you need to force the extra space, hence del list[1]
.
EDIT: You cannot redifine del
since it is a language keyword.
add a comment |
All of them are the same, del
is a keyword as yield
or return
, and (list[1])
evaluates to list[1]
. So del(list[1])
and del (list[1])
are the same. For the base case, since you dont have the ()
you need to force the extra space, hence del list[1]
.
EDIT: You cannot redifine del
since it is a language keyword.
add a comment |
All of them are the same, del
is a keyword as yield
or return
, and (list[1])
evaluates to list[1]
. So del(list[1])
and del (list[1])
are the same. For the base case, since you dont have the ()
you need to force the extra space, hence del list[1]
.
EDIT: You cannot redifine del
since it is a language keyword.
All of them are the same, del
is a keyword as yield
or return
, and (list[1])
evaluates to list[1]
. So del(list[1])
and del (list[1])
are the same. For the base case, since you dont have the ()
you need to force the extra space, hence del list[1]
.
EDIT: You cannot redifine del
since it is a language keyword.
edited Nov 15 '18 at 15:38
answered Nov 15 '18 at 15:32
NetwaveNetwave
13.5k22246
13.5k22246
add a comment |
add a comment |
The parenthehis is not mandatory with keyword (like if
or del
), but can put some if you want.
it's exactly the same thing
add a comment |
The parenthehis is not mandatory with keyword (like if
or del
), but can put some if you want.
it's exactly the same thing
add a comment |
The parenthehis is not mandatory with keyword (like if
or del
), but can put some if you want.
it's exactly the same thing
The parenthehis is not mandatory with keyword (like if
or del
), but can put some if you want.
it's exactly the same thing
answered Nov 15 '18 at 15:33
iEldeniElden
692618
692618
add a comment |
add a comment |
5
You can put parentheses in lots of places without affecting anything. Here they're simply redundant. Just like
return 1
is the same asreturn (1)
.– khelwood
Nov 15 '18 at 15:32
okay, if i write del method in my module and use the above at same time, how python interpreter differentiates between the, although i never tried until now.
– Srinivas
Nov 15 '18 at 15:34
3
Case 2 is not a function call, it is still a statement call. The same reason why
if(cond)
andif (cond)
andif cond
are all the same.– Gerges
Nov 15 '18 at 15:34
You should stick with
del ((((((((((((((((((((( list[0] )))))))))))))))))))))
;)– Chris_Rands
Nov 15 '18 at 15:35
2
You can't write a
del
function in your module.del
is a keyword.– khelwood
Nov 15 '18 at 15:37