简体   繁体   中英

input and print don't like parentheses

I have working knowledge of Python3, but I'm trying to adapt to a work environment that uses 2.7.2. Trying basic things, I can't get either input or print actions to work.

In 3.6.8 this works like so:

>> foo=("seven")
>> print("She lives with", foo, "small men")
She lives with seven small men

In my unix environment with 2.7.2, any variation using parentheses gives me a syntax error "(' is not expected". I can print without (), but I can't seem to find a way that works to assign and/or print the variable foo.

>> foo="seven"
>> print "She lives with", foo, "small men"
She lives with, foo, small men

Enclosing foo in the print statement with () [] {} or ++ all simply print whatever is typed into the code after "print". Any help is appreciated.

This turned out to be an even simpler newbie problem and fix. In the unix environment, the script needs to be preceeded with "python" at the command line. I was lulled into complacency by working in Windows previously, where the command line only required the name of the script. (Windows applies some voodoo to know to run it as python, where in unix, that'snot the case.)

Saving the same code as "foo.py" and run command with "python" yields the correct result:

=> python foo.py
She lives with seven small men

Thanks for humoring a sheepish newbie.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM