What you'll learn
What Python is, how to print text, and how to leave notes for yourself with comments.
Why it matters
Python is used for websites, data analysis, automation and AI. It is famous for being easy to read, which makes it a great first language.
Explanation
A Python program is a list of instructions that runs from top to bottom. The simplest instruction is print(), which shows something on the screen.
print("Hello, world!")- Text must be wrapped in quotes. Single
'or double"both work. print()can show several things, separated by commas:print("Age:", 30).- A line starting with
#is a comment. Python ignores it. Comments are notes for humans.
Example
# This is a comment: Python skips it
print("Hello, world!")
print("My name is", "Asha")
print("2 + 3 =", 2 + 3)Step-by-step walkthrough
- The comment line is ignored.
print("Hello, world!")showsHello, world!.- The second
printhas two items. Python puts a space between them:My name is Asha. - In the third,
2 + 3is worked out first, so it shows2 + 3 = 5.
Try it yourself
Print a sentence about yourself, then print the result of 10 * 4. The first run downloads Python into your browser, so give it a few seconds.
Hello, PythonPython
Common mistakes
- Missing quotes around text:
print(Hello)looks for a variable called Hello. - Mismatched quotes:
print("Hi')never closes the string. - Capital P:
Printis notprint. Python is case-sensitive. - Forgetting the brackets:
print "Hi"is Python 2 style and an error in Python 3.
Quick quiz
Summary
print()shows output.- Text goes in quotes;
#starts a comment. - Python runs top to bottom, one line at a time.
Next: storing values in variables.