Guide for C# developers
Python for C# Developers: Learn Python Using What You Already Know
Already know C#? Discover how familiar programming concepts translate into Python, what works differently, and the fastest path to getting productive.
C# vs Python, side by side
Each pair below does the same job. Start with the code you know, then see how Python expresses it.
Static vs dynamic typing
int count = 3;
count = "three"; // compile error
string Greet(string name) => $"Hi {name}";count = 3
count = "three" # allowed
def greet(name: str) -> str:
return f"Hi {name}"In C#, the compiler rejects count = "three". In Python a name can be rebound to any value, and types are checked only when the line runs. Type hints such as name: str are read by tools like mypy, never enforced at runtime.
Classes and properties
public class Account
{
public decimal Balance { get; private set; }
public void Deposit(decimal amount) => Balance += amount;
}class Account:
def __init__(self):
self.balance = 0
def deposit(self, amount):
self.balance += amountPython uses a plain attribute where C# uses an auto-property, and you can switch to @property later without changing callers. There is no private set; a leading underscore, as in _balance, marks something as internal by convention.
LINQ vs comprehensions and generators
var names = people
.Where(p => p.Active)
.Select(p => p.Name)
.ToList();names = [p.name for p in people if p.active]
# lazy: nothing runs until you iterate it
active = (p for p in people if p.active)A list comprehension builds the whole list at once, like ToList(). A generator expression in parentheses is lazy, but it can be consumed only once, unlike a LINQ query you can enumerate again. They are not one-to-one: for GroupBy or OrderBy you will use dictionaries and sorted.
async/await
async Task<string[]> FetchAllAsync(IEnumerable<string> urls)
{
return await Task.WhenAll(urls.Select(FetchAsync));
}import asyncio
async def fetch_all(urls):
return await asyncio.gather(*(fetch(url) for url in urls))Both use async and await, but a Python coroutine does nothing until it is awaited or scheduled, for example with asyncio.run(...), while a C# Task starts running as soon as it is created. asyncio is single-threaded, so it suits waiting on I/O rather than CPU-heavy work.
What C# developers need to unlearn
A few habits carry over badly. These shifts matter most.
Indentation is the syntax
Blocks start with a colon and are defined by indentation instead of braces. Use four spaces and stay consistent.
Types are checked at runtime
Dynamic typing means a name can refer to any value, and type errors appear when the line runs. Optional type hints plus a checker such as
mypybring back some of C#'s safety.Comprehensions replace most LINQ
A comprehension such as
[p.name for p in people if p.active]covers the commonWhereandSelectchains in one readable line.Lean on built-in collections
Lists, dictionaries, sets and tuples cover most of what you reach for in
System.Collections.Generic. Useinto test membership andlen(items)instead of aCountproperty.Write Python, not C# in Python
Skip getters, setters and one-method classes. Use
withwhere you would useusing, and write names insnake_caseinstead ofPascalCase.
Your C#-to-Python learning roadmap
Translate familiar concepts
Map familiar syntax and concepts to Python.
Learn Python's differences
Collections, functions, idiomatic style.
Practice with real code
Solve small problems, not just read.
Build confidence
Harder, more realistic challenges.
Hintor's Python for Developers track is designed for developers switching languages, with hands-on practice built into the lessons. Explore the Python for Developers track
Mini challenge
Given a list of integers, write Python code that creates a new list containing the squares of only the even numbers.
- Input
- [1, 2, 3, 4, 5, 6]
- Expected output
- [4, 16, 36]
Hint: a list comprehension can include an if filter, and n % 2 == 0 tests whether n is even.
numbers = [1, 2, 3, 4, 5, 6]
even_squares = [n * n for n in numbers if n % 2 == 0]
print(even_squares) # [4, 16, 36]The comprehension reads left to right: compute n * n for each n in numbers, keeping only the even ones. A regular for loop with append works too; the comprehension is the idiomatic shortcut.
Ready to Turn Your C# Knowledge into Python Skills?
You already know how to program. Now learn to think in Python with guided lessons and hands-on practice.
Start Learning Python on Hintor