Python for the .NET developer Transcripts
Chapter: The Python Language
Lecture: Language features we will cover
0:00 Before we get into the details
0:01 let's just briefly look at
0:03 the various language features of Python
0:05 that we're going to cover, and how those map back to C#.
0:09 We're going to start by talking
0:10 about the language structure itself
0:12 what holds the language together and defines its elements.
0:16 And in C# we have things like curly braces, and semicolons.
0:20 Python has neither of those.
0:23 So, how do you define, like, an if statement
0:25 or a function or a class, stuff like that?
0:27 So this is what we're going to start focusing on.
0:30 Then I want to cover loops.
0:32 C# and Python have a lot of similarities
0:34 but there's also a few unique and powerful features to loops
0:38 in Python that we want to look at, because they're not obvious
0:41 until you've had some time to work with the language
0:43 and they're really powerful.
0:45 Functions, functions are first class objects in Python
0:49 similar to C#, but C#, all functions
0:52 have to be contained within a class.
0:53 Python, not so much, so they're a little more flexible
0:56 in that regard.
0:57 Generators, lazy functions, things that use the yield return
1:02 keyword in C#, or maybe the LINQ extension methods
1:05 like Where and Select and so on.
1:08 You'll see that Python has something like this as well
1:11 these great functions that are super easy
1:13 to turn into iterators or generators
1:16 so we're going to definitely talk about that.
1:18 Ternary conditional expressions, delegates
1:21 some of the terminology I'm using here is C# terminology
1:24 but that's not what they're called in Python.
1:26 But since you are C# developers
1:28 I'm going to speak your language as much as possible
1:31 when we get started here.
1:32 How do we define a function that can be passed
1:34 as an argument or accepted as an argument?
1:36 Some of the best delegates are lambda expressions
1:39 these short little functions that you can pass along
1:42 without going to all the trouble
1:43 to create separate functions.
1:45 See, Python has great support for those as well.
1:47 Closures, when a function captures data and holds onto it
1:51 for the lifetime of that function
1:53 which is pretty interesting.
1:55 Type systems and runtime types
1:58 think of Python as a dynamic language
2:00 but actually all the runtime elements do have types
2:03 and there's actually some static typing
2:04 that we can use in the language.
2:07 Error handling and exceptions, a lot of similarities here.
2:10 Using blocks, the idea of
2:12 for this little block of code, even within a function
2:14 just a smaller block to find it
2:17 using context where code is going to run
2:19 and then outside of that
2:20 something important's going to happen.
2:22 A file's going to be closed, transaction will be rolled back
2:25 something like that.
2:26 We'll see how we work with these types of constructs
2:29 IDisposable, and so on, in Python.
2:31 Finally, the switch statement.
2:34 Python itself doesn't have a switch statement
2:36 but because it's a very flexible language
2:38 there's some really cool things we can make, like almost
2:40 like language switch statements.
2:42 So, you'll see you can do some really
2:44 interesting things there.
2:46 Now if you look at this list, these are a lot of the things
2:48 that you probably think, oh, these are really important
2:50 to me in C#
2:51 and every one of them has a great implementation in Python.
2:56 See something missing there? What about classes?
2:59 Do we have classes in here? No. Don't worry.
3:03 Python, of course, has classes
3:05 in object oriented programming, and all that kind of stuff.
3:07 Because it is important, we're going to treat that
3:10 as its own separate chapter.
3:11 So we're going to over the idea of classes here
3:14 but that's not because they don't exist
3:15 that's because we're actually treating them
3:17 with a little extra love and care later.