This series on AI is going to take two paths:
- Writing prompts
- Writing apps that integrate AI (see Hypervideo)
If you are writing apps, you have a couple choices (well, more than a couple). One choice is to stay in the Azure/.NET world, in which case C# is just fine. The other (set of) choice(s) is to work in the rest of AI development, in which case Python is the language of choice.
I’m taking a course on agentics from Johns Hopkins University, and that course is in Python. It turns out that learning Python is pretty easy if you are a C# programmer, and it is even easier if you are a C# programmer with access to CoPilot and/or ChatGPT for Python.
I resisted learning Python all these years, but I’ve come to believe that if you are serious about AI then Python is in your future. So, might as well bite the bullet and get started now.
It’s Just Syntax
All the concepts are the same (more or less). There are variables, loops, dictionaries, tuples and so forth. Some of the syntax is different (no braces) and some of the rules vary a bit (tuples are immutable), but it won’t take you long to learn. Let’s start with the basics.
DataTypes: Python has only three numeric datatypes: int, float and complex. It also has str (string) and bool. One thing to watch for is truthy v true. True requires a bool but truthy is anything that evaluates to true. Huh? If a variable is of type bool, it can only. have one of two values: true or false. But an expression can evaluate to true (e.g., 5+7 = 12) which is truthy.
There are also collections. some are ordered: list (which is mutable), tuple (which is not mutable) and range (which is an immutable arithmetic progression). In addition, there is dict — a dictionary which works much like a dictionary in c#
If you need a dictionary with unique values, there is the set, which comes in two flavors: set (mutable) and frozenset (immutable)
Finally, None does the work of void
According to ChatGPT the core types you’ll use 90% of the time are:
- int
- float
- str
- bool
- list
- dict
- tuple
- set
- none
which pretty much corresponds to the big types in c# (except, perhaps set).
Indentation One big thing for C# programmers to watch out for is indentation. Python does not use braces in if statements, functions, etc.; it uses indentation.
if (myAge > 5)
print("You are a big boy")
else
print("You still have some growing to do")
print("But don't worry, we all went through it")
print("this line is not in the if/else")
Notice that the last print statement is not in the if/else construct. Oh, there is also an elif statement so that you can have if, elif, elif, else.
Function definition You define a function with the keyword def and you use indentation to set the contents of the function:
def greet(name):
print("Hello")
print(name)
Some quick rules on indentation:
- Typically you indent 4 spaces (but that is not really a rule)
- All indentation must be the same amount
- You cannot mix tabs and spaces
Don’t forget to nest your indentation
def check_age(age):
if age >= 21:
print("Can drink")
else:
print("Cannot drink")
Lists Lists are created with square brackets
numbers = [10, 20, 30, 40]
Notice you do not put the type. You never declare the type, it is inferred. (this is true for all declarations, not just collections)
You iterate over lists with a very similar syntax to C#’s foreach
for number in numbers:
print(number)
Don’t forget the colon!
Dictionaries Dictionaries are similar to lists, but you declare them with curly braces. You iterate over them using the key and the value:
students = {
1001: "Alice",
1002: "Bob"
}
for student_id, name in students.items():
print(student_id, name)
This will print
1001 Alice
1002 Bob
You can access both with .items() or the keys with .keys() or the values with .values()
Tuples Tuples can be declared with or without parentheses
coordinates = (15, 20)
colors = ("red", "greeen", "blue", "yellow")
point = 5,10
You can iterate over a tuple
for color in colors:
print(color)
A common thing to do with tuples is called unpacking. For example, using the point from above, you can write
point = (10, 20)
x, y = point
print(x) # 10
print(y) # 20
Or you can use this in loops, which is a common construct
pairs = ((1, "A"), (2, "B"), (3, "C"))
for number, letter in pairs:
print(number, letter)
That’s plenty to get you started with Python. Of course there are more advanced constructs, and we’ll tackle them as we go, but these are the fundamentals.





































