Congratulations on taking your first step into the exciting world of Python programming! This guide is designed to take you from absolute beginner to a comfortable intermediate Python user. We'll start with the very basics, and before you know it, you'll be building your own programs.
Every programming journey begins with a single step, and in Python, that step often involves making your computer speak. The most classic way to do this is by printing a greeting to the screen. This simple act is incredibly powerful as it introduces you to the fundamental concept of output.
The command you'll use to display text or other information is called print(). Think of it as telling Python: 'Hey, show this to me!' Inside the parentheses, you put what you want to be displayed. For text, we enclose it in quotation marks. Let's try the most famous first program:
print("Hello, World!")When you run this code, your computer's output will be:
Hello, World!Simple, right? You've just written and executed your very first Python program! This print() function is your primary tool for seeing the results of your code and understanding what's happening as your programs grow more complex.
Beyond just text, Python can work with different kinds of data, known as 'data types'. For now, let's touch upon the most basic ones you'll encounter immediately: strings (text) and numbers. The print() function can handle both!
Numbers in Python can be integers (whole numbers like 10, -5, 0) or floating-point numbers (numbers with a decimal point like 3.14, -2.5, 0.0). Notice that we don't use quotation marks around numbers when we want Python to treat them as numerical values.
print(42)
print(3.14159)The output of the above code will be:
42
3.14159You can also combine strings and numbers in your print statements, although we'll learn more about formatting later. For now, just know that print() is versatile and is your window into your program's execution. Keep experimenting with printing different kinds of messages and numbers!