Before doing anything else in a new programming language, you traditionally make it say “Hello world”. In Python that’s a one-liner:
print("Hello world")The print() function sends whatever you give it straight to the console.
You can ask Python to repeat a string by multiplying it:
print("example " * 5)That prints one line containing the word example five times.
- Create a new file called
Task_1.pyin your editor. - Write the lines shown below.
- Run the file from your terminal or IDE and watch the output.
print("Hello world")
print("example " * 5)Hint: Text must always be wrapped in quotes (
' 'or" "). Forgetting them makes Python think it’s a variable name and you’ll get an error.