Python for the .NET Developer Transcripts
Chapter: Course conclusion
Lecture: Python language review

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The first technical topic that we covered was the Python language and how it is similar and how it is different than C#.
0:08 We talked about the language structure, and C# my description here, the language structure is defined by curly braces that define blocks
0:16 semi colons that define end of line. Python, as you know by now, has neither of those which is honestly a little bit crazy.
0:24 It's also useful once you get used to it. With the way we define language structure in Python is we have code indented, spaces, blocks of four spaces
0:32 four, eight, twelve, and so on and then those blocks are begun by having some statement colon.
0:38 Like while true colon, indent, and then there's the loop. Speaking of loops, Python has two basic kinds of loops. While loops, and for in loops
0:47 those are the equivalent of C#s or each loops. Prominently missing here is the for i=0, i<limit i++ type of numerical for loop, but we saw we can
0:59 kind of accomplish that with ranges or a blend of the two using enumerated collections. Python has good support for functions that are
1:07 first class functions. We can even define generators with the yield keyword and C# it's yield return in Python it's just yield.
1:16 We also have a ternary expression in Python these are more English like, remember, small if number is less than 100. Else, huge.
1:26 We can pass around functions that can be called and C# we create we do this by creating a delegate that matches the structure and
1:33 defines basically the type of function you're passing around by the arguments that go in and the
1:37 arguments that are returned by, those that do not come out. In Python we don't define delegates exactly like that
1:43 we can just take the function name and pass it around. Sometimes, we want to just define little functions.
1:49 In C# we have lambda expressions. They're super awesome! In Python, we have lambda expressions, they're super awesome.
1:55 Instead of having those arrows, arguments goes to you know, equals greater than expression, which is the C# way, in Python we have the word lambda
2:03 arguments, colon, expression return by. We also have closures in both languages where we're capturing ambient local values maybe a function
2:11 within a function, we're capturing that intermediate value there that is odd, kind of amazing, it gets
2:16 hung onto, it's kept as persistent ambient information for that function over time. Remember our counter object.
2:22 We can add types called type annotations or type hints in Python. It really makes it a lot nicer I think especially with
2:31 the right tooling like Pie Charm or VS Code. To see those and go Aha, here's the auto complete list
2:36 for one of those, I didn't realize that's what it was but now that you tell me I can give you a lot more help.
2:41 We also have runtime type information in Python. Everything has a type, everything is an object just like C#, it's more the language, the static
2:50 type system that code writing and compilation time that is the big difference here. Error handling is actually super similar between
2:57 both try catch finally C# try accept finally in Python. You throw exceptions in C# you raise exceptions in Python.
3:08 We saw that using blocks were great for discreet blocks of code where something is true, a file is open but then it is closed.
3:15 Database connection is open but then it is rolled back if there's an error. With Python we have context managers in the width block, same basic idea.
3:23 And finally, I threw in switch. Python doesn't have switch, but I made a switch and I like it a lot so I think it's a cool addition
3:29 to the language and it actually doesn't take any changes to the language, it just uses those with blocks that I told you about just now.
3:36 All right, whew, remember this was a long chapter and it's a bit of a long review. Just to go over this cause there was a lot there.
3:44 One of the main takeaways I hope is there's so many cool features of the C# language then you put it side by side with Python, you're like
3:50 like wow, Python has actually almost every single one of those features in very very comparable or comfortable ways.
3:57 I think Python's a beautiful language and hopefully this comparison gave you a sense of that beauty.


Talk Python's Mastodon Michael Kennedy's Mastodon