Python 3 Build in and Reserved Keywords

Python 3 Build in and Reserved Keywords

In this post, I’m gonna give you the list of Python 3 reserved keywords. This list is handy when you will be creating variables, function names, and classes.

It would also help while crafting documentation and code for fellow developers to avoid making references to the concepts that are not related and could cause confusion.

Knowing these keywords will not only make you a better Python programmer but will also make you look more mature as a programmer.

Newbie coders often forgot that the particular word is a reserved keyword, and create confusing names for functions and variables. They don’t know or remember all the abstractions enclosed in the programming language. And it’s common for inexperienced developers. You don’t want to be perceived as one of them, do you?

The list is not hard to remember, but it doesn’t make sense to learn it. Instead, read it once or twice, and go back to it every time you need to refresh your memory while working with the code.

Over time you will notice that you will know every element on the list without learning it.

The list is grouped by the context where a particular keyword can occur.

Special values

Module
  • async
  • await
  • import - used to import the content of the module into the current module
  • as - used together with ‘import’ specifies an alias for imported module
  • from - used together with ‘import’, it specifies the module to import, and ‘import’ specifies what functions will be imported
  • def - define function
  • pass - skip the function definition
  • return - return value from the function
  • lambda - used for creating anonymous, inline functions, without self parameter
  • global - used for declaring a variable inside a function as global (as it was declared outside the function)
  • nonlocal - marks the variable that it refers to the variable defined outside the function, used only when we change the value in nested function (closures)
  • if - starts a conditional block
  • else - alternative block in a conditional block
  • elif - alternative conditional block with condition check
  • is - returns true if two objects are the same

Logical operators

  • and - expression result into True only if both operands are True
  • or - expression result into True only if any of operands is True
  • not - expression result into True only if the operand is False
  • in - used to test if a sequence (string, list, tuple) contains a value
  • for - starts for loop block
  • while - starts while loop block
  • break - exit execution of the loop
  • continue - skips current loop iteration and go to the next one

Control flow

  • with - declares a control-flow structure
  • as - used together with ‘with’
  • try - starts try/except block
  • raise - throws an exception
  • except - starts specific exception handling block
  • finally - starts block executed after the try/except block execution is finished
  • class - used to declare a class
  • pass - used to declare that child class will have the same declaration as it’s parent class
  • del - deletes the class
  • del - deletes the variable or removes value from the sequence (list, tuple, string)
  • yield - pauses generator execution and returns the value
  • assert - declares assertion condition

Conclusion

The list of Python keywords is a good asset to have on hand. Even experienced programmers forget some of these keywords.

To our advantage, Python doesn’t have many built-in keywords, and they are very easy to remember when you craft a lot of code on a daily basis.

If you have any questions related to this post, leave the comment below.

If you found this post helpful, consider sharing it, so I will be motivated to publish more posts that will help you get the IT career you want.

As always, stay focused!

Link copied to clipboard