[root@stvz stvz]# python3
Python 3.2.1 (default, Jul 11 2011, 18:55:33)
[GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> var = '1'
>>> if var == '1':
...     print('algo')
... elif var =='2':
...     print('otra cosa')
...
algo
>>>


El 25/02/12 11:30, mauricio rodriguez escribió:
[mcun@RUN ~] <$>  python
Python 3.2.2 (default, Nov 21 2011, 16:50:59)
[GCC 4.6.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> var = '1'
>>> if var == '1'
  File "<stdin>", line 1
    if var == '1'
                ^
SyntaxError: invalid syntax
>>> var = '1'
>>> if var == '1':
...     print ('algo')
... elif var == '2':
...     print 'otra cosa'
  File "<stdin>", line 4
    print 'otra cosa'
                    ^
SyntaxError: invalid syntax

?¿?¿

evalúa la sentencia de elif  ¿?


El 25 de febrero de 2012 15:26, Jhonny5 <jhon...@gmail.com <mailto:jhon...@gmail.com>> escribió:

    Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
    [GCC 4.5.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> var = '1'
    >>> if var == '1':
    ...     print ('algo')
    ... elif var == '2':
    ...     print 'otra cosa'
    ...
    algo



    saludos,
    j.

    2012/2/25 mauricio rodriguez <rodriguez.maurici...@gmail.com
    <mailto:rodriguez.maurici...@gmail.com>>

        disculpen me equivoque al tipear var es un string

        el ejemplo seria así

        var = '1'
        if var == '1':
            print ( 'algo')
        elif var == '2':
            print 'otra cosa '

        el error me lo marca en elif ya que print lo pues
        sin paréntesis y corro la versión 3 de python

        de allí mi pregunta porque evalúa la sentencia de elif si
        la condición de elfi no se cumple

        gracias por su tiempo



        El 25 de febrero de 2012 15:17, Juan José Gómez Romera
        <jjgom...@gmail.com <mailto:jjgom...@gmail.com>> escribió:



            El 25 de febrero de 2012 17:54, Alvaro Manrique
            <sanreikaj.fo...@gmail.com
            <mailto:sanreikaj.fo...@gmail.com>> escribió:

                Otra cosa, el print puedes dejarlo sin los paréntesis,
                no va a cambiar el funcionamiento
                solo que es mas acostumbrado sin ellos.


            Si usas python 3 no es cuestión de costumbre, es
            obligatorio usarlos ;)

            _______________________________________________
            Python-es mailing list
            Python-es@python.org <mailto:Python-es@python.org>
            http://mail.python.org/mailman/listinfo/python-es
            FAQ: http://python-es-faq.wikidot.com/



        _______________________________________________
        Python-es mailing list
        Python-es@python.org <mailto:Python-es@python.org>
        http://mail.python.org/mailman/listinfo/python-es
        FAQ: http://python-es-faq.wikidot.com/




-- talueee.com <http://talueee.com/>

    Linux User #236965 (linuxcounter.net <http://linuxcounter.net>)
    key: http://talueee.com/gpg/jhonny5.asc
    fingerprint = 9ACC 8E56 F40B 27A5 977C  49E6 F896 511E 657A E933
    Po fueno, po fale, po malegro.


    _______________________________________________
    Python-es mailing list
    Python-es@python.org <mailto:Python-es@python.org>
    http://mail.python.org/mailman/listinfo/python-es
    FAQ: http://python-es-faq.wikidot.com/




_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

Responder a