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