Keywords:

Keywords in Python are reserved words that have special meanings and predefined functionalities within the Python language.
 
These keywords cannot be used as identifiers (variable names, function names, class names, etc.). They are specifically designated for certain purposes.
 

These keywords serve various purposes in python as below:

Control Flow: Keywords like if, else, elif, for, while, break, continue, and pass are used for control flow statements and loops.

Function and Class Definitions: Keywords such as def and class are used to define functions and classes respectively.

Logical Operators: Keywords like and, or, not are used as logical operators for Boolean expressions.

Exception Handling: Keywords such as try, except, finally, raise are used for exception handling.

Importing Modules: Keywords like import and from are used to import modules and packages into the Python script.

Boolean Values: Keywords True and False represent the Boolean values in Python.

It is important to note that keywords are case-sensitive and cannot be used as variable names or identifiers in Python programs.

Attempting to use a keyword as an identifier will result in a syntax error as below:

 

#Assigning value to class keyword

class = 45
Output:
  File "<ipython-input-5-d49a1984b151>", line 1
    class = 45
          ^
SyntaxError: invalid syntax
  • Let’s see all keywords of python
import keyword

print('All keywords of python : ',keyword.kwlist)
print('Total number of keyword :',len(keyword.kwlist))
Output:
All keywords of python :  ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Total number of keyword : 35

Register

Login here

Forgot your password?

ads

ads

I am an enthusiastic advocate for the transformative power of data in the fashion realm. Armed with a strong background in data science, I am committed to revolutionizing the industry by unlocking valuable insights, optimizing processes, and fostering a data-centric culture that propels fashion businesses into a successful and forward-thinking future. - Masud Rana, Certified Data Scientist, IABAC

© Data4Fashion 2023-2024

Developed by: Behostweb.com

Please accept cookies
Accept All Cookies