DEV Community

Cover image for Lesson 1 - Python Basics: Print, Syntax & First Programs
Nitin S Kulkarni
Nitin S Kulkarni

Posted on

Lesson 1 - Python Basics: Print, Syntax & First Programs

1. Concept Overview

Python is a high-level, interpreted programming language designed to be:

  • easy to read
  • easy to write
  • powerful enough for real-world systems

In Python, we write instructions line by line, and Python executes them from top to bottom.

This lesson introduces:

  • how Python programs start
  • how output is displayed
  • the basic rules Python strictly follows

2. Metal Model (How to think About it)

Think of Python as a very strict English-speaking assistant:

  • It follows instructions in order
  • It cares deeply about spelling and indentation
  • If it doesn’t understand a line, it stops immediately and complains

Your job as a programmer is to give clear, correctly formatted instructions.

3. Your First Python Program

The simplest valid Python program:


print("Hello, World!")

Enter fullscreen mode Exit fullscreen mode

What is happening here?

  • print → a built-in Python function
  • () → used to pass information to the function
  • "Hello, World!" → a string (text data)

When this program runs, Python displays:


Hello, World!

Enter fullscreen mode Exit fullscreen mode

4. The print() Function

The print() function is used to display output on the screen.

Printing Text


print("Welcome to Python")

Enter fullscreen mode Exit fullscreen mode

Printing Numbers


print(10)
print(3.14)

Enter fullscreen mode Exit fullscreen mode

Python understands numbers without quotes.

5. Printing Multiple Values

You can print multiple values at once:


print("Age:", 21)
print("Sum:", 10 + 5)

Enter fullscreen mode Exit fullscreen mode

Python automatically separates values with a space.

6. Printing on the Same Line

By default, print() moves to a new line after execution.

You can control this using end:


print("Hello", end=" ")
print("World")

Enter fullscreen mode Exit fullscreen mode

Output:


Hello World

Enter fullscreen mode Exit fullscreen mode

7. Escape Characters

Escape characters allow special formatting inside strings.


print("Hello\nWorld")
print("Python\tProgramming")
print("She said \"Hello\"")

Enter fullscreen mode Exit fullscreen mode
Escape Meaning
\n New line
\t Tab space
\" Double quote

8. Comments in Python

Comments are ignored by Python and used for humans.


# This is a comment
print("Python ignores comments")

Enter fullscreen mode Exit fullscreen mode

Use comments to:

  • explain logic
  • document code
  • temporarily disable code

9. Python Syntax Rules (Very Important)

Python is case-sensitive:


print("Hello")   # Correct
Print("Hello")   # Error

Enter fullscreen mode Exit fullscreen mode

Python uses indentation, not braces {}.

Every statement must follow Python’s syntax exactly.

10. Common Beginner Mistakes

  • Missing quotes:
print(Hello)
Enter fullscreen mode Exit fullscreen mode
  • Wrong brackets:
print["Hello"]
Enter fullscreen mode Exit fullscreen mode
  • Capitalization error:
Print("Hello")
Enter fullscreen mode Exit fullscreen mode

These cause syntax errors, and the program will not run.

11. Practice Problems

Easy

  • Print your name.
  • Print your city.
  • Print your age.

Medium

  • Print the following output exactly:
Python
is
awesome
Enter fullscreen mode Exit fullscreen mode
  • Print:
I am learning "Python"
Enter fullscreen mode Exit fullscreen mode

Thinking Practice

Fix the errors:

print("Hello World)
Print("Python")
print("Done"]
Enter fullscreen mode Exit fullscreen mode

12. Mini Task

Create a console introduction card:

Name: Rahul
Age: 22
Course: Python
Enter fullscreen mode Exit fullscreen mode

Rules:

Use only print()

No variables yet

13. Interview Corner

Q1. What is Python?

Expected answer:
Python is a high-level, interpreted programming language.

Q2. What does print() do?

Expected answer:
It displays output on the screen.

Q3. Is Python case-sensitive?

Expected answer:
Yes, Python is case-sensitive.

Q4. What are comments?

Expected answer:
Lines ignored by Python, used to explain code.

Q5. What type of error occurs if syntax is wrong?

Expected answer:
SyntaxError.

14. Key Takeaways

  • Python executes code line by line

  • print() displays output

  • Strings must be inside quotes

  • Python is strict about syntax and case

  • Errors are normal and part of learning

Next Lesson

Lesson 2 – Variables & Data Types

Top comments (1)

Collapse
 
swap29feb profile image
swapnil thorat

Very informative.. keep posting weekly. Loved your content.