Your First Steps in Python: A Beginner to Intermediate Guide

The `print()` Function: Your First Command

Section 2

Your First Python Program: Printing and Basic Data Types

Your First Steps in Python: A Beginner to Intermediate GuideYour First Python Program: Printing and Basic Data Types

Welcome to the exciting world of Python programming! Every journey begins with a single step, and in Python, that step is often using the print() function. Think of print() as your way of talking to the computer. It's the primary tool you'll use to display information, test your code, and see the results of your commands.

The basic syntax for the print() function is simple. You type print, followed by a pair of parentheses (). Inside these parentheses, you place whatever you want the computer to display. This could be text, numbers, or even the results of calculations.

print()

Let's try printing some text. Text in Python, and many other programming languages, is called a 'string'. Strings are enclosed in quotation marks. You can use either single quotes (') or double quotes (") to define a string. Both will work perfectly fine, but it's good practice to be consistent within your project.

print('Hello, Python!')

When you run this line of code, Python will interpret the print() command and display the text 'Hello, Python!' exactly as it's written inside the quotes, on your screen or in your console.

print("This is also a string!")

You can also use print() to display numbers. Numbers are not enclosed in quotes because they are treated as numerical values, not as sequences of characters. This allows Python to perform mathematical operations on them later on.

チャプターへ戻る