osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python "Bad syntax"


On Tue, Feb 6, 2018 at 4:28 AM, Phil Boutros <philb at philb.ca> wrote:
> <darkorbitaknaentou at centrum.cz> <darkorbitaknaentou at centrum.cz> wrote:
>>
>> Hi, I have a problem in continuing the function.
>>
>> I'm a beginner, I'm learning from a textbook. I'm going to put the
>> following examples from a textbook that displays "wrong syntax"
>>
>>>>> for letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
>>             if letter in "AEIOU":
>>                 print(letter, "is a vowel")
>>            else:
>>                  print(letter, "is a consonant")
>>
>> In this text, I will write a "wrong syntax" after confirming the
>> "else" function. How is it possible? Using the Bad Version of
>> Python? Please, please, thank you very much!
>
>     Which version of python are you using?  That syntax for "print"
> started in python 3 (since print became a function).
>
> Try adding:
>
> from __future__ import print_function
>
> before your code if you're still using python 2.x
>

It would still be valid syntax in Python 2 - it'd just print out a tuple.

ChrisA