{"id":23892,"date":"2021-10-05T17:58:54","date_gmt":"2021-10-05T12:28:54","guid":{"rendered":"https:\/\/python-programs.com\/?p=23892"},"modified":"2021-10-14T10:00:12","modified_gmt":"2021-10-14T04:30:12","slug":"python-keywords-and-identifiers","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-keywords-and-identifiers\/","title":{"rendered":"Python \u2013 Keywords and Identifiers"},"content":{"rendered":"

In this article we are going to discuss about keywords and identifiers in Python.<\/p>\n

Keywords are prearranged and predefined words in python. Every keywords are written in lower case except True and False. If we count there are 33 keywords in python. Keywords are case sensitive. We can not create any function or identifiers with matching keyword name. I python these keywords are\u00a0 made for particular purpose.<\/p>\n

All Python Keywords are listed below:<\/p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
1<\/td>\nand<\/strong><\/td>\nIt is a logical operator. If both the operands are true it returns true otherwise false.<\/td>\n<\/tr>\n
2<\/td>\nOr<\/strong><\/td>\nIt is also a logical operator. Returns true if anyone operand is true otherwise return false.<\/td>\n<\/tr>\n
3<\/td>\nnot<\/strong><\/td>\nThis is again a logical operator. Returns True if the operand is false else return false.<\/td>\n<\/tr>\n
4<\/td>\nif<\/strong><\/td>\n\u00a0Conditional statement.<\/td>\n<\/tr>\n
5<\/td>\nelif<\/strong><\/td>\nElif is a condition statement used with if statement the elif statement is executed if the previous conditions were not true<\/td>\n<\/tr>\n
6<\/td>\nelse<\/strong><\/td>\nElse is used with if and elif conditional statement the else block is executed if the given condition is not true.<\/td>\n<\/tr>\n
7<\/td>\nfor<\/strong><\/td>\nThis is created for a loop.<\/td>\n<\/tr>\n
8<\/td>\nwhile<\/strong><\/td>\nThis keyword is used to create a while loop.<\/td>\n<\/tr>\n
9<\/td>\nbreak<\/strong><\/td>\nThis is used to terminate the loop.<\/td>\n<\/tr>\n
10<\/td>\nas<\/strong><\/td>\nThis is used to create an alternative.<\/td>\n<\/tr>\n
11<\/td>\ndef<\/strong><\/td>\nIt helps us to define functions.<\/td>\n<\/tr>\n
12<\/td>\nlambda<\/strong><\/td>\nIt used to define the anonymous function.<\/td>\n<\/tr>\n
13<\/td>\npass<\/strong><\/td>\nThis is a null statement that means it will do nothing.<\/td>\n<\/tr>\n
14<\/td>\nreturn<\/strong><\/td>\nIt will return a value and exit the function.<\/td>\n<\/tr>\n
15<\/td>\nTrue<\/strong><\/td>\nThis is a Boolean value.<\/td>\n<\/tr>\n
16<\/td>\nFalse<\/strong><\/td>\nThis is also a Boolean value.<\/td>\n<\/tr>\n
17<\/td>\ntry<\/strong><\/td>\nIt makes a try-except statement.<\/td>\n<\/tr>\n
18<\/td>\nwith<\/strong><\/td>\nThe with keyword is used to simplify exception handling.<\/td>\n<\/tr>\n
19<\/td>\nassert<\/strong><\/td>\nThis function is used for debugging purposes. Usually used to check the correctness of code<\/td>\n<\/tr>\n
20<\/td>\nclass<\/strong><\/td>\nIt helps us to define a class.<\/td>\n<\/tr>\n
21<\/td>\ncontinue<\/strong><\/td>\nIt continues to the next iteration of a loop<\/td>\n<\/tr>\n
22<\/td>\ndel<\/strong><\/td>\nIt deletes a reference to an object.<\/td>\n<\/tr>\n
23<\/td>\nexcept<\/strong><\/td>\nUsed with exceptions, what to do when an exception occurs<\/td>\n<\/tr>\n
24<\/td>\nfinally<\/strong><\/td>\nFinally is use with exceptions, a block of code that will be executed no matter if there is an exception or not.<\/td>\n<\/tr>\n
25<\/td>\nfrom<\/strong><\/td>\nThe form is used to import specific parts of any module.<\/td>\n<\/tr>\n
26<\/td>\nglobal<\/strong><\/td>\nThis declares a global variable.<\/td>\n<\/tr>\n
27<\/td>\nimport<\/strong><\/td>\nThis is used to import a module.<\/td>\n<\/tr>\n
28<\/td>\nin<\/strong><\/td>\nIt\u2019s used to check if a value is present in a list, tuple, etc, or not.<\/td>\n<\/tr>\n
29<\/td>\nis<\/strong><\/td>\nThis is used to check if the two variables are equal or not.<\/td>\n<\/tr>\n
30<\/td>\nNone<\/strong><\/td>\nThis is a special constant used to denote a null value or avoid. It\u2019s important to remember, 0, any empty container(e.g empty list) do not compute to None<\/td>\n<\/tr>\n
31<\/td>\nnonlocal<\/strong><\/td>\nIt\u2019s declared a non-local variable.<\/td>\n<\/tr>\n
32<\/td>\nraise<\/strong><\/td>\nThis raises an exception<\/td>\n<\/tr>\n
33<\/td>\nyield<\/strong><\/td>\nIt\u2019s ends a function and returns a generator.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Python Identifiers<\/h3>\n

Python identifiers are generally used to recognize a variable, function, class etc. There are some rules which we should follow while choosing a name for identifier-<\/p>\n

1.Identifier should start with a character or Underscore after that use digit.<\/p>\n

2.Characters are A-Z or a-z, an Underscore ( _ ) , and digit (0-9).<\/p>\n