https://wiki.cabal.mx/index.php?title=Curso_de_Programaci%C3%B3n_en_Python/Set-7&feed=atom&action=history
Curso de Programación en Python/Set-7 - Historial de revisiones
2024-03-29T10:50:10Z
Historial de revisiones para esta página en el wiki
MediaWiki 1.32.1
https://wiki.cabal.mx/index.php?title=Curso_de_Programaci%C3%B3n_en_Python/Set-7&diff=6807&oldid=prev
Rrc en 19:47 25 nov 2014
2014-11-25T19:47:00Z
<p></p>
<p><b>Página nueva</b></p><div>__NOTOC__<br />
* [[:#Set-7 | Set-7.py]]<br />
** [[:#Resultado | Resultado]]<br />
<br />
== Set-7.py ==<br />
<br />
<syntaxhighlight lang="python" line="GESHI_FANCY_LINE_NUMBERS"><br />
#!/usr/bin/python3<br />
#-*-coding: utf-8 -*-<br />
<br />
Animales = { "Gato", "Perro", "Agaporni", "Lobo" }<br />
print( "Animales:", Animales )<br />
<br />
# Tiramos lo que no existe.<br />
Animales.discard( "Cebra" )<br />
print( "Animales:", Animales )<br />
<br />
Animales.discard( "Gato" )<br />
print( "Animales:", Animales )<br />
<br />
Animales.remove( "Agaporni" )<br />
print( "Animales:", Animales )<br />
<br />
# Remove nos da un error si el elemento no existe.<br />
Animales.remove( "Ballena" )<br />
print( "Animales:", Animales )<br />
<br />
</syntaxhighlight><br />
<br />
=== Resultado ===<br />
<br />
<pre><br />
[rrc@Llawyr PythonClase]$ ./Set-7.py <br />
Animales: {'Gato', 'Perro', 'Lobo', 'Agaporni'}<br />
Animales: {'Gato', 'Perro', 'Lobo', 'Agaporni'}<br />
Animales: {'Perro', 'Lobo', 'Agaporni'}<br />
Animales: {'Perro', 'Lobo'}<br />
Traceback (most recent call last):<br />
File "./Set-7.py", line 18, in <module><br />
Animales.remove( "Ballena" )<br />
KeyError: 'Ballena'<br />
</pre><br />
<br />
[[Category:Programación en Python]]<br />
[[Category:PythonCabal]]<br />
[[Category:CursoPython]]</div>
Rrc