Python is an unambiguous, easy-to-read, general-purpose high-level programming language which considers paradigms of structured, procedural, and object-oriented programming.
Python is a high level language that is interpreted. This means that you type in your program and run it without having to compile it first. This makes Python quick to develop. Python is also cross platform compatible. This means that a Python program written on a Windows machine will also run on a Mac or Linux machine without any changes being made to the code.
There are two main versions of Python that are currently available: Version 2 and Version 3. Version 2 is legacy at this point and will eventually be phased out. All new development should be done using Version 3. In this tutorial, we will be using Version 3.
Identifiers and keywords are the building blocks of any programming language. They are used to create variables and constants which store data that can be used by the program. In this tutorial, we will take a look at what identifiers and keywords are in Python, how they are used, and what rules need to be followed when naming them.
An identifier is a name given to an entity in a program. They are used to name variables, constants, functions, classes, and modules. An identifier can be made up of letters (both upper and lower case), digits, and the underscore (_) character. They cannot start with a digit though. Here are some examples of valid identifiers:
my_variable
myVariable123
MY_VARIABLE_1
_myVariable1
__myvariable2__
__init__ (this is actually a special keyword)
As you can see from the examples above, identifiers can be of any length and can contain both letters and numbers. The only restriction is that they cannot start with a number (other than __init__ which is a special case). Most programming languages have similar rules for identifiers. It’s always best to choose names for your identifiers that are descriptive so that it’s clear what they are being used for when reading your code later on. This makes your code easier to read and maintain.
In Python, there are 33 keywords that have special meaning and cannot be used as identifiers:
False await else import pass
None break except in raise
True class finally is return
async def for lambda try Nonlocal
assert del from nonlocal while continue elif global not with finally else if or yield as except import lambda while break except ImportError as e: … from … import * except Exception as inst: … except BaseException: … except (RuntimeError,) as e :… for … in range(5): … class C(object): staticmethod(f) @staticmethod def f(): … lambda x: x**2 map(lambda x: x**2,[1]) filter(lambda x: x > 0,[-1,-2])