By Leonardo Zeaiter
Part 1 of 5 in a free introductory series, laying the groundwork for my forthcoming book: *Python Beyond Syntax: Advanced Topics for the C# Developer*.
It's worth noting that everything covered in this series is intentionally a quick, practical introduction, enough to get you reading and writing basic Python comfortably, not a complete treatment of any single topic. Think of this series as learning to hold a conversation; the book is where you become fluent. Python Beyond Syntax: Advanced Topics for the C# Developer takes everything you already know from years of C# and uses it as the map for learning Python properly: not just syntax, but the reasoning behind async, memory management, object-oriented design, generators and the idioms that make Python code actually look like Python. Each topic is explored in both languages side by side, so you always know exactly where your existing instincts hold and where they'll mislead you. And because Python is the language behind nearly every AI tool and library worth knowing, this isn't just a second language, it's your fastest path to being dangerous with AI development without starting from zero.
Why you're here
You didn't wake up one day and decide you needed a new hobby. You're exploring this series because Python has quietly become the language every interesting conversation in tech seems to run through: AI, data, automation, the tools you keep seeing in demos that make you think "wait, how did they do that so fast?" And somewhere in the back of your mind is a small, slightly annoying voice saying: I should probably know this, not just nod along.
The good news is this: you're not starting from zero. You're starting from 5 (or 10, or 3) years of already knowing what a variable is, what a loop does, why functions exist, and how to think like a programmer. You're not learning to code. You're learning Python's accent, a new way of saying things you already know how to say.
Before We Start: Running Python in VS Code
You probably already have VS Code installed; let's get it running Python so you can then try each example as we go.
1. Install Python itself. VS Code edits code, but it doesn't run Python on its own; you need to install Python on your machine first. Download it from https://python.org by grabbing the latest stable version and run the installer. On Windows, make sure you tick "Add python.exe to PATH" during setup. Skipping it is the most common reason Python "doesn't work" afterward.
2. Install the Python extension. Open VS Code, click the Extensions icon in the left sidebar (or press Ctrl+Shift+X / Cmd+Shift+X), search for "Python" (the official one, published by Microsoft), and click Install. This gives you syntax highlighting, autocomplete, and the ability to run Python files directly from the editor, the same kind of experience you're used to with C# in Visual Studio.
3. Create and run a file. Create a new file, name it hello.py and type:
print("Hello from Python")
Then run it by clicking the Run button that appears in the top-right corner of the editor.
A terminal panel opens at the bottom of VS Code and you'll see Hello from Python printed out. That terminal is running your actual code.
1. Indentation Replaces { }
In C#, curly braces mark where a block starts and ends. Indentation is optional and its presence improves readability; for the compiler, it is meaningless.
if (isReady)
{
Console.WriteLine("Let's go");
}
Python skips the braces entirely and uses indentation itself to mark the block:
if is_ready:
print("Let's go")
The colon (:) says: a block is coming, and the indented lines underneath are that block. Stop indenting, and you're back outside it. That's really all there is to it: you already indent your C# code this way out of habit, and Python just makes it official.
The convention is 4 spaces per indentation level (a tab works too, just don't mix tabs and spaces in the same file). Most editors can be set to insert spaces automatically when you press Tab, which makes this a non-issue.
In C#, an empty block is represented by curly braces with no code inside. Since braces are omitted altogether in Python, you must use the keyword pass to declare an empty block as follows:
if is_ready:
pass
2. Data Types: Less Ceremony, Same Idea
In C#, you're used to declaring a variable's type up front:
int score = 95;
double average = 87.5;
string name = "John";
bool isActive = true;
Python skips the type declaration entirely:
score = 95
average = 87.5
name = "John"
is_active = True
The variable still has a type. Python figures it out at runtime from the assigned value; score is an int, average is a float, name is a str, is_active is a bool, exactly as you'd expect. This is called dynamic typing, in contrast to C#'s static typing.
Python's core built-in types map onto what you already know from C#:
| Python type | Roughly equivalent to | Example |
|---|---|---|
int |
int / long
|
42 |
float |
double / float
|
3.14 |
str |
string |
"hello" |
bool |
bool |
True / False
|
NoneType |
null |
None |
Since Python doesn't ask you to declare a type, you'll often want to check what type a value actually is, especially while you're still getting a feel for the language. The built-in type() function tells you:
score = 95
print(type(score)) # <class 'int'>
print(type(score) == int) # True
average = 87.5
print(type(average) == float) # True
name = "John"
print(type(name) == str) # True
type(x) == int is a handy way to check what a variable actually holds while you're experimenting; a genuinely useful habit while you're exploring how Python treats values.
Hint: think of a C# variable as a labeled box that can only ever hold one specific type of thing; you painted "int" on the box, and only ints go in it. A Python variable is more like a sticky note. It just points at whatever value you last assigned, and you can point it at something else entirely, including a different type, without Python complaining:
value = 42
print(type(value) == int) # True
value = "now I'm a string" # perfectly legal, no error
print(type(value) == str) # True
This flexibility is genuinely useful for fast exploratory scripting and this is the kind of thing Python was built for; however, this also means you'll lose an important feature you already have in C#: the compiler's ability to catch type mistakes at build time.
3. Naming Conventions
Python has its own naming conventions, and they differ from what you're used to in C#. Adopting them early will save you from writing code that technically works but visibly looks like it was written by someone new to the language.
-
Variables and functions use
snake_case:is_active,user_name,calculate_total(). -
Classes use
PascalCase, same as C#:class OrderProcessor:,class UserAccount:. -
Constants are typically written in
ALL_CAPS_WITH_UNDERSCORES:MAX_RETRIES = 5, similar in spirit to C#'s convention forconstfields.
Nobody will stop you from writing camelCase variables in Python; it'll just immediately mark your code as written by someone new to the language.
4. if, elif, and the Vanishing Parentheses
You already know exactly what this does:
if (temperature > 30)
{
Console.WriteLine("Hot");
}
else if (temperature > 15)
{
Console.WriteLine("Mild");
}
else
{
Console.WriteLine("Cold");
}
Here's the same logic in Python:
if temperature > 30:
print("Hot")
elif temperature > 15:
print("Mild")
else:
print("Cold")
Three small differences: no parentheses required around the condition, elif instead of else if (one word, not two), and, same as before, the colon and indentation replace the curly braces entirely.
5. Loops: for Works Like Your foreach
Python's for loop is close to C#'s foreach: it walks through a sequence directly, rather than managing a counter by hand the way C#'s classic for does.
for i in range(5):
print(i)
range(5) produces the sequence 0, 1, 2, 3, 4, and the loop walks through it, printing each value in turn. If you're looping over a collection you already have, it reads just as naturally:
names = ["Alice", "Bob", "Charlie"]
for name in names:
print(name)
This is exactly your foreach (var name in names) instinct from C#, just with slightly leaner syntax.
Python's while loop will feel completely familiar with zero adjustment:
count = 0
while count < 5:
print(count)
count += 1
Note: Python has no ++ or -- operators. count += 1 is legal and commonly used.
Two more keywords worth knowing right away, since you'll use them constantly. break and continue work exactly as they do in C#, break exits the loop entirely, continue skips to the next iteration:
for i in range(10):
if i == 3:
continue # skip 3, move to the next number
if i == 6:
break # stop the loop entirely once we hit 6
print(i)
# prints: 0, 1, 2, 4, 5
6. Comments: The One Genuine Simplification
C# gives you two styles:
// single line
/* multi
line */
Python gives you one primary style for single-line comments:
# single line
For multi-line comments, Python doesn't have a true dedicated block-comment syntax. The common convention is a triple-quoted string left standalone in the code, which Python happily ignores if it's not assigned to anything:
"""
This isn't officially a "comment."
It's a string literal Python evaluates and discards,
but it's used as a stand-in for block comments.
"""
Nothing to overthink here: the # symbol will cover 95% of your commenting needs.
7. Truthy and Falsy: Where Python Gets a Little Philosophical
This is the one concept in this article that's genuinely new, not just a syntax reshuffle. It's worth understanding properly, because it quietly affects how you'll write conditions in Python from here on.
In C#, an if condition must evaluate to an actual bool. You can't casually stick an int or a string into an if and have it just work the way you might in some looser languages.
Python is far more permissive: any value can be evaluated in a boolean context, and each type has rules for what counts as "truthy" (treated as true) or "falsy" (treated as false):
name = ""
if name:
print("Has a name")
else:
print("Empty!") # this runs; an empty string is falsy
The general rule: False, 0, 0.0, "" (empty string), [] (empty list), {} (empty dict), () (empty tuple) and None are all falsy. Pretty much everything else, True, non-zero numbers, non-empty strings, non-empty collections is truthy.
This lets you write idiomatic Python like:
items = []
if items:
print("We have items")
else:
print("The list is empty") # this runs
instead of the more verbose, C#-flavored:
if len(items) > 0:
...
Both work. The first is how experienced Python developers actually write it, and recognizing it when you read someone else's code is at least as important as being able to write it yourself.
8. Basic Input and Output
Last thing for this article, and the simplest: printing output and reading input.
print("Hello, John")
name = input("What's your name? ")
print("Nice to meet you, " + name)
print() is your Console.WriteLine(). input() is your Console.ReadLine(), with one convenience built in: it takes an optional prompt string to display before waiting for input, saving you a separate print() call.
What You Can Already Do
Stop and notice something: with just what's in this article, you can already write a Python script with variables, conditionals, and loops, which, syntax aside, is genuinely most of what a program is.
Next up, Article 2 covers the most common data structures in Python: lists, dictionaries, tuples, and sets. You'll notice that they are genuinely more flexible than what you're used to in C#, not just different.
If you'd like early access to my forthcoming book: Python Beyond Syntax: Advanced Topics for the C# Developer, kindly sign up at https://tally.so/r/9q5l2Q.
Top comments (0)