[Tutor] help
Peter Otten
__peter__ at web.de
Tue Feb 5 09:15:35 EST 2019
Sonia Miglani wrote:
> Hi Team,
>
> I am learning puthon and trying the following code.
>
> But getting the following error.
>
> Please help me in knowing the code in better way.
>
>
> OS Linux
> Python version 2.7.13
>
>
>
> def demo(s, exclaim):
> # """
> # Returns the string 's' repeated 3 times.
> # If exclaim is true, add exclamation marks.
>
>
> result = s + s + s
> if exclaim:
> result = result + '!!!'
> return result
>
>
> def main():
> print demo('Yay', False) ## YayYayYay
> print demo('Woo Hoo', True) ## Woo HooWoo HooWoo Hoo!!!
>
>
> Error:
> ./python2.py: line 1: syntax error near unexpected token `('
That is not a Python error, that's a complaint of your shell.
If you make a Python script executable you also have to insert the proper
hash-bang line. In the case of Python 2
#!/usr/bin/python2
will probably work. Example shell session:
$ cat tmp.py
def demo():
print "heureka"
demo()
$ ./tmp.py
./tmp.py: line 1: syntax error near unexpected token `('
./tmp.py: line 1: `def demo():'
$ cat tmp2.py
#!/usr/bin/python2
def demo():
print "heureka"
demo()
$ ./tmp2.py
heureka
$
> ./python2.py: line 1: `def demo(s,exclaim):
>
>
>
>
>
> Regards
> Sonia
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list