Introduction
Introduction
Introduction
In this lesson, you'll learn about introduction in Python. Coming from C#, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.
In C#, you're familiar with introduction.
Python has its own approach to introduction, which we'll explore step by step.
The Python Way
Let's see how Python handles this concept. Here's a typical example:
print("Hello, World!")Comparing to C#
Here's how you might have written similar code in C#:
using System;
class Hello {
static void Main() {
Console.WriteLine("Hello, World!");
}
}You may be used to different syntax or behavior.
No class, no Main, no braces — Python runs top-level code directly
You may be used to different syntax or behavior.
Indentation (4 spaces) defines code blocks instead of curly braces
You may be used to different syntax or behavior.
Python is interpreted — no compile step; run with 'python file.py'
You may be used to different syntax or behavior.
No semicolons at line endings
You may be used to different syntax or behavior.
print() replaces Console.WriteLine()
Step-by-Step Breakdown
1. No Entry Point Class
C# requires all code to live inside a class and a Main method. Python executes top-level statements directly. The 'if __name__ == __main__' guard is optional but conventional.
class Program {
static void Main() {
Console.WriteLine("Hello");
}
}# Top-level code runs directly
print("Hello")
# Conventional guard for reusable scripts:
if __name__ == "__main__":
print("Running as script")2. Indentation Instead of Braces
Python uses consistent indentation (PEP 8 recommends 4 spaces) to define blocks. Mixing tabs and spaces is a syntax error.
if (x > 0) {
Console.WriteLine("positive");
x++;
}if x > 0:
print("positive")
x += 13. print() vs Console.WriteLine
print() is a built-in function. It prints to stdout with a trailing newline by default. You can change the separator and end characters.
Console.WriteLine("Hello");
Console.Write("no newline");
Console.WriteLine($"x = {x}");print("Hello")
print("no newline", end="")
print(f"x = {x}") # f-string interpolation4. Running Python Code
Python is interpreted — there is no compile step. Just run the file directly with the Python interpreter.
// C#: dotnet build && dotnet run
// or: csc Program.cs && Program.exe# Python: just run it
# python hello.py
# python3 hello.py (on some systems)
# Interactive REPL
# python
# >>> print("Hello")Common Mistakes
When coming from C#, developers often make these mistakes:
- No class, no Main, no braces — Python runs top-level code directly
- Indentation (4 spaces) defines code blocks instead of curly braces
- Python is interpreted — no compile step; run with 'python file.py'
Key Takeaways
- No class or Main required — top-level code runs directly
- Indentation (4 spaces) replaces curly braces
- print() replaces Console.WriteLine(); f-strings replace $"..."
- No compile step — run with 'python file.py'