How to discard (remove) element that exists in a set using Python

2 Answers

0 votes
st = {"python", "c++", "java", "php"}

print(st)
st.discard("java")
print(st)


'''
run:

{'php', 'python', 'c++', 'java'}
{'php', 'python', 'c++'}

'''

 



answered Sep 15, 2018 by avibootz
0 votes
st = {"python", "c++", "java", "php"}

print(st)
st.remove("php")
print(st)


'''
run:

{'c++', 'php', 'python', 'java'}
{'c++', 'python', 'java'}

'''

 



answered Sep 15, 2018 by avibootz

Related questions

1 answer 268 views
2 answers 368 views
3 answers 384 views
1 answer 300 views
2 answers 366 views
...