All 39 Python Keywords Explained

preview_player
Показать описание
In today’s video we will be learning about all the 39 keywords that exist in Python (as of 3.12). I will be covering each one very briefly, so you will probably have to do your own research if you feel like learning more about these!

▶ Become job-ready with Python:

▶ Follow me on Instagram:

00:00 Learning Python made simple
00:05 Intro
01:12 False
01:43 None
02:34 True
03:10 and
04:07 as
05:18 assert
06:49 async
07:24 await
08:35 break
09:05 class
09:30 continue
10:58 def
11:22 del
11:58 elif
12:42 else
12:54 except
13:27 finally
13:49 for
14:10 from
14:34 global
15:31 if
16:04 import
16:28 in
17:05 is
18:18 lambda
19:51 nonlocal
21:05 not
22:18 or
23:15 pass
24:00 raise
24:18 return
25:08 try
26:14 while
27:20 with
28:31 yield
29:34 _
30:50 case
31:24 match
32:28 type
32:58 Soft keywords
33:40 Outro
Рекомендации по теме
Комментарии
Автор

I think you're much too harsh on bob at 9:45.
bob has helped in so much of my coding. Always been there at the frontlines, takes any assignment I hand out, and successfully completes tasks, or faithfully reports errors encountered.
Justice for bob!

cerealport
Автор

Some complement:

A and B -> (B if A else A)
A or B -> (A if A else B)

bool(0) -> False
bool(“”)-> False
bool([])-> False
bool(None)-> False
bool(“ “)-> True

code after else that after while, for, try except
will only be executed when the loop or the try is finish normally (not normal: break, error)

verysb
Автор

Excellent video. Thanks for sharing your knowledge!

cyberhard
Автор

Python in 34 minutes. Incredible!! And perfectly explained as always 👍

WinfriedKastner
Автор

4:07 you also use "as" with "except" to assign the exception to a variable

AJMansfield
Автор

Thank you I really am beginning to appreciate material that is more focused on thinking, and Python. I’ve learned a lot from tutorials, but for the most part, I am only able to apply what I have copied and limited situation versus having an understanding and being able to create.

anthonydrakefordshadow
Автор

I have never heard of several of these despite taking a few Python courses... I am intrigued

Celemimphar
Автор

I'm I the only one finding this video funny.
Very comprehensive video.
I love it.😅

ImportCode
Автор

Really appreciate your effort. More videos like this please!!!

rakibmasud
Автор

Why is it that all programming teachers I know are calmest most chill and nice people yet they casually drop the darkest type of humour or life truths :D

PCgmesforever
Автор

33:12

type type = int | float
match: type = 10
case: type = 10.0

match match:
case case:
print(f"types {type} are the same because case {case} matches {match}")

Keventor
Автор

You can also use the from keyword to yield from an iterator: yield from iterator

cuicuidev
Автор

Built-in constants:
* `False`
* `None`
* `True`
Built-in functions:
* `assert`
* assert is simply a built-in function that doesn't require parenthesis; you could write your own function, `my_assert`, that does the same thing
* `type`
* unlike `assert`, you can override `type`
Imports:
* `import`
* `from` - must be followed by `import`
* `as` - must be proceeded by `import` or `with`
Declarations:
* `class`
* `def`
* `async` - must be followed by `def`
* `del`
* Scope changes:
* `global`
* `nonlocal`
Logical operators:
* Unary:
* `not`
* Binary:
* `and`
* `in`
* `is`
* `or`
* Ternary:
* `if` and `else` - must be used together, like this:
* `(when_true) if (condition) else (when_false)`
Expression:
* `lambda`
* allows you to make a 1-line function that returns the value on the line without declaring the function
* very
Control:
* `pass`
* actually does nothing
* typically used to put an empty body in a control block, function, or class
* Logic
* `if`
* `else`
* `elif`
* Loops:
* `for`
* `while`
* `continue`
* `break`
* Error handling:
* `try`
* `except` - must be proceeded by `try`
* `finally` - must be proceeded by `try` or `except`
* `raise`
* Functions:
* `return`
* `yield`
* makes the function return a generator, even if the code around `yield` is not accessible
* this items in this generator are all of the values of each `yield` statement
* if the function hits a `return` statement, the generator will stop / finish and ignore the rest of the function; further attempts to generate items from the generator will fail because it is finished and the GC might have deleted the function call stack that the generator used
* Async:
* `await`
Switch statenements:
* `case`
* `match`
Bad
* `with`
* `with A as B: C` does this:
* run `A`
* set `B =` return value of `A`
* run `B.__enter__()`
* try to run `C`
* if an exception occurs, run `B.__exit__(self, exception_type, exception_val, trace)`
Doesn't do anything and is not a constant
* `_`
* essentially not a keyword

simonwillover
Автор

Really nice video with the explanations about built in keywords in python. I appriciate your efford.

flaminggasolineinthedarkne
Автор

Thank you for all the excelente work! Great video 👌🏼

max_unch
Автор

What about the other uses of else? Like for ... else, while ... else, try ... except ... else?

joshix
Автор

dude this is amazing thank you so much

lucasmandato
Автор

At 33:33 you can't do that. Doing "case case:" will match any number (not just 10) and put it in the variable case. I think that's why your editor is underlining it.

datanasov
Автор

Some useful details:
( Better to write this down before I forget something )
"and"/"or" : because of the short circuit system, these can return any object (non booleans).
"None": while these represent the absence of a value (like null in other languages), it doesn't mean that every non declared name equals None. It's more of a special value that any object can take. (btw if we use types, by default it's incorrect to assign None). Also we must be careful when writing "assert x" or "if x:" when we want to check for None, because if x is equal to False, it will act as if it is None. This depends on the __bool__ method of the object in question.
Asserts: I've read that they only work if __debug__ is True, so I'm instead using "if x: raise Exception".
"del": a non recommended keyword. Its behavior depends on the object involved. If it's a list item, del will remove it from lists.
"pass": avoid filling placeholders with pass, since you won't be able to differentiate what is supposed to do nothing (for example, an abstract method) and what has its implementation pending. I prefer to "raise NotImplementedError()"

alejandroherme
Автор

Amazing job buddy. Thank you very much for all your hard work! You are amazing and I am defo gonna buy one of your paid tutorials.

velovelo