[pyar] Duda: str.upper("string") vs "string".upper()

Edgardo edgardolor en gmail.com
Vie Nov 8 17:02:29 -03 2019


@ <augusto_prigioni en itrsa.com.ar>Augusto gracias por tu pronta respuesta,
mira:


[image: imagen.png]

Creo que en uno de los libros recomendados por Python Arg esta el método
que intente inicialmente.

El vie., 8 nov. 2019 a las 16:52, Augusto (<adtononi en gmail.com>) escribió:

> Te habrás confundido con otro lenguaje. En Python solo está el método
> string.upper(), por lo que no hay diferencia, simplemente existe un solo
> método válido.
>
> El vie., 8 nov. 2019 16:48, Edgardo <edgardolor en gmail.com> escribió:
>
>> Buenas tardes,
>>
>> Estoy siguiendo el curso de Georgia Institute of Technology en EDX y en
>> el capitulo de manejo de errores me piden crear el siguiente código:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *#Write some code that will capitalize and print the value of#the_string.
>> For example, for the initial value of the_string#above, it should print
>> "I'M A RAMBLIN' WRECK".#You can capitalize a string by calling
>> the_string.upper().#This will return a capitalized version of the string.
>> (Note#that this will _not_ modified the_string, but rather just#return the
>> result if it were to be capitalized.)#However, the_string might not
>> actually be a string! It might#be an integer, a float, or something else.
>> If that happens,#then calling the_string.upper() will cause an
>> AttributeError#to occur. Catch this error and print "The variable was not#a
>> string!"#Note that you may not use any conditionals in your answer.#Note
>> also that you should not assume that every error that#occurs is an
>> Attribute Error! Any other errors should#not be caught.*
>>
>> Mi intento inicial fue:
>>
>> *the_string = "I'm a Ramblin' Wreck"*
>>
>>
>>
>>
>> *try:    print(str.upper(the_string))except AttributeError:    print("The
>> variable was not a string!")*
>>
>> El mismo arroja un error de TypeError, al parecer str.upper() solo acepta
>> como argumento, el tipo de datos string
>>
>> Al modificar el código a:
>>
>>
>>
>>
>>
>> *try:    print(the_string.upper())except AttributeError:    print("The
>> variable was not a string!") *
>>
>> El mismo corre con éxito (el ejercicio atrapa todos las excepciones de
>> tipo AttributeError)
>>
>> Alguien seria tan amable de explicarme la diferencia entre AMBOS MÉTODOS?
>>
>> No recuerdo de donde saque str.upper("cadena") pero por lo visto me quedo
>> porque fue mi primer intento, pero al buscar en info en google solo
>> encuentro referencias al metodo "cadena".upper()
>>
>>
>> Muchas gracias.
>> _______________________________________________
>> Lista de Correo de PyAr - Python Argentina - pyar en python.org.ar
>> Sitio web: http://www.python.org.ar/
>>
>> Para administrar la lista (o desuscribirse) entrar a
>> http://listas.python.org.ar/listinfo/pyar
>>
>> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
>> Argentina - http://www.usla.org.ar
>
> _______________________________________________
> Lista de Correo de PyAr - Python Argentina - pyar en python.org.ar
> Sitio web: http://www.python.org.ar/
>
> Para administrar la lista (o desuscribirse) entrar a
> http://listas.python.org.ar/listinfo/pyar
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20191108/59c2ef70/attachment-0001.html>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: imagen.png
Type: image/png
Size: 9610 bytes
Desc: no disponible
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20191108/59c2ef70/attachment-0001.png>


Más información sobre la lista de distribución pyar