Keywords, Operators in Python
Keywords, Operators in Python
A class is a blueprint or template for creating objects. It defines a set of attributes (variables)
and methods (functions) that the objects created from the class will have.
• Attributes: Variables that belong to the class and define the properties of objects.
• Methods: Functions defined inside a class that describe the behaviors or actions of
the objects.
For example, think of a class like a blueprint for a car: it defines what a car is (color, model,
etc.) and what a car can do (drive, stop, etc.).
Object:
An object is an instance of a class. When you create an object, you're essentially building a
specific car from the blueprint (class). Each object can have its own specific values for the
attributes defined by the class.
Key Points:
Keywords:
Python has a set of keywords that are reserved words that cannot be used as variable names,
function names, or any other identifiers:
Here is a list of Python keywords, which are reserved words and cannot be used as identifiers,
variable names, or function names:
Keyword Description
False Boolean value representing falsehood.
None Represents a null value or absence of a value.
True Boolean value representing truth.
and Logical operator; returns True if both operands are true.
as Used to create an alias, often in import or with statements.
assert Tests if a condition is true; raises an error if false.
async Declares an asynchronous function.
await Pauses execution in an async function until completion.
break Exits a loop prematurely.
Keyword Description
class Defines a class.
continue Skips the current loop iteration and moves to the next.
def Defines a function.
del Deletes objects, variables, or elements from a collection.
elif Else-if condition in conditional statements.
else Default condition in conditional statements.
except Catches and handles exceptions in a try block.
finally Executes code after try, regardless of exceptions.
for Starts a loop over a sequence.
from Imports specific parts of a module.
global Declares a variable as global.
if Starts a conditional statement.
import Imports a module or objects from a module.
in Tests membership in a sequence or iterable.
is Tests object identity.
lambda Creates a small anonymous function.
nonlocal Refers to a variable in an outer but non-global scope.
not Logical negation operator.
or Logical operator; returns True if either operand is true.
pass A placeholder that does nothing.
raise Raises an exception.
return Exits a function and optionally returns a value.
try Starts a block for exception handling.
while Starts a loop that continues as long as the condition is true.
with Wraps code in a context manager.
yield Pauses a function and returns a value; used in generators.
Python Operators
In Python, operators are special symbols used to perform operations on variables and values.
Here's a breakdown of the different types of operators:
1. Arithmetic Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operators
6. Identity Operators
7. Membership Operators