Your first line of Python
print, and the four separate things happening inside one very short line.
The most useful thing a very fast helper can do at first is tell you something. You give it a message and it says the message back. That sounds trivial, and it is the thing you will use most often for the rest of your life as a programmer, because it is how you find out what your program is actually doing.
In Python the instruction for saying something is called print, which is a slightly old-fashioned name: nothing goes near a printer. It writes the message into the output, which in this course is the panel underneath the code.
print("Hello.")Four separate things are in that line, and each one has a job.
- `print` is the name of the instruction. It has to be spelled exactly like that, all in lower case.
- The round brackets hold whatever you are handing to
print. They come in a pair, and the closing one has to be there. - The quotation marks say: what is between us is text, not an instruction. They are the fence around the message.
- `Hello.` is the message itself. It can be anything: a word, a sentence, a shopping list.
A piece of text like that is called a string, because it is a string of characters, one after another, in order. A character is a single letter, digit, space or mark of punctuation. "Hello." is a string of six characters, counting the full stop.
Change the message and run it again. Then try one with a comma and a question mark in it: punctuation inside the quotation marks is just more text.
Python accepts single quotation marks as well as double ones. The only rule is that both ends have to match.
Change one of the single quotes to a double quote and run it again. Then change the other one to match, and run it once more.
The choice matters in one situation. If the message itself contains an apostrophe, use double quotation marks around it, otherwise Python thinks the apostrophe is the end of the string.
Change the double quotes at each end to single quotes and run it. Python will stop partway along the line. Nothing is broken: put the double quotes back and it works again.