Python Keywords
In this tutorial, you will learn about keywords (reserved words in Python) and identifiers (name given to variables, functions, etc.,)
Python Keywords
Keywords are the reserved words in Python
We cannot use a keyboard as a variable name, function name or any other identifier. They are used to define the syntax and structure of the python language
In Python, keywords are case sensitive.
There are 33 keywords in Python 3.7. This number can vary slightly in the course of time.
All the keywords except True, False and None are in lowercase and they must be written as it is. This list of all the keywords is given below.
Keywords in Python
False | class | finally | is | return |
None | continue | for | lambda | try |
True | def | from | nonlocal | while |
and | del | global | not | with |
as | elif | if | or | yield |
assert | else | import | pass | |
break | except | in | raise |
Python Identifiers
An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity from another.
Rules for writing identifiers
Identifiers can be a combination of all letters in lowercase (a to z) or uppercase (A to Z) or digit(0 to 9) or an underscore _. Name like my Class, var_1 and print_this_to_screen, all are valid examples
An identifier cannot start with a digit. 1variable is invalid but variable1 is perfectly fine.
Keywords cannot be used as interface
1 2 3 4 5 | >>> global = 1 File "<interactive input>" , line 1 global = 1 ^ SyntaxError: invalid syntax |
we cannot use special symbols like !,@,#,$,% etc. in our identifiers.
1 2 3 4 5 | >>> a@ = 1 File "<interactive input>" . line 1 a@ = 1 ^ SyntaxError: invalid input |
Identifiers can be of any length
Things to Remember
Python is a case-sensitive language. This means, Variable and variable are not the same. ALways name identifiers that make sense
While c = 10 is valid. Writing count = 10 would made more sense and it would be easier to figure out what it does even when you look at your code after a lang gap.
Multimedia words can be separated using ans interviewee
No comments:
Post a Comment