Course 1.1Lesson 3 of 5
Quotation marks make text, which print() shows as it is. Without quotation marks, Python calculates a sum and shows the answer. print() puts one space between pieces that are separated by commas. The option sep changes what goes between the pieces, and end changes what comes after the last piece. An empty print() makes a blank line. Text can use single or double quotation marks, and a new line inside text is written with a backslash and the letter n.
Try the code and the simulations beside the lesson.
After this lesson you can
print() shows for each,print(),Look at these three lines. They look almost the same.
This is one of the first things that a programmer learns to see: quotation marks mean "this is text". Without them, Python tries to understand what you wrote.
The rule is the same for every sign: with quotation marks it is text, without them it is a sum.
You can also write sep="", with nothing between the quotation marks, to join the pieces with no space.
What if the text has a quotation mark inside it? The apostrophe in Asha's is a single quotation mark. If you put it inside single quotation marks, Python thinks that the text ended. The simple way out is to use the other kind of marks outside.
The third line shows a new line inside text. The two signs \n (a backslash and the letter n) mean "start a new line here". So one print() can make two or three lines.
print(Hello) is an error, and print("2 + 3") shows the text, not 5.print() adds a new line. Use end="" when you want the next output on the same line.print("Total:", 5) shows Total: 5. print("Total:" + 5) is an error. We study why in the next courses.Start with two quick questions. Each New numbers gives you a fresh one, so you can practise as long as you like.
Then the labs and the problems:
1 | 2 | 3 | 4, using only one print().sep changes it, and end changes what comes after.\n starts a new line.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
print("a", "b") show? What does print("a", "b", sep="") show?print("4 * 2") and print(4 * 2)?print("one", end=" ") and then print("two") show?print() that shows It's 5 o'clock.Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.