Basic Python Hello World Program Syntax Error

倾然丶 夕夏残阳落幕 提交于 2019-12-17 21:13:06

问题


I am not that really new in Programming but in Python I am really a newbie, and so when I started learning Python from the tutorials they encouraged me to use the IDLE editor for Python. And so as a newbie I had this weird Hello World problem.

as you can see i use Python 2.6.6 in Linux(CentOS 6.2)

and I tried almost all the possible syntaxes printing the simple HELLOWORLD provided in the documentation of python 2.6 and the new python 3

I tried printing contants like this

print 1 + 1

and it work with an output

>>> 2

I want to know how can i print this simple HELLOWORLD


回答1:


Check to make sure that you are really using straight quotes. Some programs/systems automatically replace them with curly quotes.

Here try copy pasting this and running it:

print "hello"

If this turn's out to be an issue then you might want to ask at https://unix.stackexchange.com/ how to disable such a feature.




回答2:


It looks like you're typing different double-quotes than what Python requires. Maybe your IME has "smart quotes" turned on or something? Anyway, you could try:

print 'hello world'

using single quotes (really, the apostrophe character) as an alternative. If you can't make that work, then copy and paste what I've written in this answer and that should work.

Here's one with double quotes for you to copy too:

print "hello world"



回答3:


You need to use single (') or double (") quotes, not fancy quotes or diaereses as you did.

print "Hello, World!" 



回答4:


IF you have copy-pasted the code from a CHM / PDF file then be aware of the quotes. What appears as single / double quotes in the pdf is not treated as quotes in the text editor/shell etc.

type out the code on the py shell. it should work!




回答5:


The problem here is with the double quotes. Try to use a different word editor , it will surely solve the problem. For Linux , install gedit and then type the code and run it. For Mac, Install Text Wrangler and For Windows , Install Notepad++.

This will definitely solve your problem.



来源:https://stackoverflow.com/questions/8736952/basic-python-hello-world-program-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!