FUNCTIO
FUNCTIO
Keywords
ython has36 reserved keywordsthat are part of the language’s syntax and cannot be
P
used as variable names:
●
False
: Boolean value indicating false.
●
None
: Represents the absence of a value.
●
True
: Boolean value indicating true.
●
and
: Logical operator.
●
as
: Used in context management and imports.
●
assert
: Used for debugging and testing.
●
async
: Declares an asynchronous function.
●
await
: Awaits the result of an async function.
●
break
: Exits the current loop.
●
class
: Declares a class.
●
continue
: Skips the current iteration of a loop.
●
def
: Declares a function or method.
●
del
: Deletes a variable or element.
●
elif
: Else-if condition in control flow.
●
else
: Else condition in control flow.
●
except
: Handles exceptions in try-except blocks.
●
finally
: Final block in exception handling.
●
for
: Defines a for-loop.
●
from
: Specifies the module to import from.
●
global
: Declares a global variable.
●
if
: Conditional statement.
●
import
: Imports modules.
●
in
: Checks membership in sequences.
●
is
: Compares object identities.
●
lambda
: Declares an anonymous function.
●
nonlocal
: Refers to a variable in an enclosing scope.
●
not
: Logical negation.
●
or
: Logical operator.
●
pass
: Does nothing (placeholder).
●
raise
: Raises an exception.
●
return
: Returns a value from a function.
●
try
: Defines a try block for exception handling.
●
while
: Defines a while-loop.
●
with
: Handles resources, often used with file operations.
●
yield
: Returns from a generator function.
●
print()
: Outputs text or variables.
●
input()
: Reads user input.
●
open()
: Opens a file and returns a file object.
●
int()
: Converts to an integer.
●
float()
: Converts to a float.
●
str()
: Converts to a string.
●
bool()
: Converts to a Boolean value.
●
list()
: Converts to a list.
●
tuple()
: Converts to a tuple.
●
set()
: Converts to a set.
●
dict()
: Converts to a dictionary.
●
bin()
: Converts an integer to binary.
●
hex()
: Converts an integer to hexadecimal.
●
oct()
: Converts an integer to octal.
●
abs()
: Absolute value.
●
round()
: Rounds to a given precision.
●
pow()
: Exponentiation (with modulus option).
●
sum()
: Sum of items in an iterable.
●
min()
: Minimum of iterable.
●
max()
: Maximum of iterable.
●
divmod()
: Returns quotient and remainder.
●
len()
: Length of an object.
●
str()
: Converts to string.
●
format()
: Formats a string.
●
ord()
: Converts a character to its ASCII value.
●
chr()
: Converts an ASCII value to a character.
●
len()
: Length of an object.
●
sorted()
: Returns a sorted list.
●
enumerate()
: Adds index to iterable.
●
map()
: Applies a function to each item of an iterable.
●
filter()
: Filters an iterable based on a function.
●
zip()
: Aggregates iterables.
●
keys()
: Returns keys of a dictionary.
●
values()
: Returns values of a dictionary.
●
items()
: Returns key-value pairs.
●
range()
: Generates a sequence of numbers.
●
iter()
: Returns an iterator.
●
next()
: Fetches the next item from an iterator.
●
lambda
: Anonymous function.
●
map()
: Applies a function to all items in an iterable.
●
filter()
: Filters elements in an iterable based on a condition.
●
reduce() functools
: Reduces an iterable to a single value (from ).
●
any() Trueif any element is
: Returns True
.
●
all() Trueif all elements are
: Returns True
.
●
type()
: Returns the type of an object.
●
isinstance()
: Checks if an object is an instance of a class.
●
dir()
: Lists the attributes of an object.
●
id()
: Returns the identity of an object.
●
hash()
: Returns the hash value of an object.
●
callable()
: Checks if an object is callable.
●
open()
: Opens a file.
●
read()
: Reads content from a file.
●
write()
: Writes content to a file.
●
close()
: Closes a file.
K. Miscellaneous
●
eval()
: Evaluates a string as a Python expression.
●
exec()
: Executes Python code dynamically.
●
help()
: Provides help information.
●
globals()
: Returns the global symbol table.
●
locals()
: Returns the local symbol table.
●
memoryview()
: Returns a memory view object.
●
try except
, finally
, : Handles exceptions.
●
raise
: Manually raises an exception.
●
assert
: Debugging aid that raises an error if condition is false.
ython comes with extensive standard libraries and modules. Some key built-in modules
P
include:
●
math
: Provides mathematical functions.
●
random
: Generates random numbers.
●
datetime
: Handles dates and times.
●
sys
: Provides access to system-specific parameters.
●
os
: Provides functions for interacting with the operating system.
●
functools reduce()
: Provides higher-order functions like .
●
itertools
: Provides iterator-building functions.
●
collections deque
: Provides specialized data structures (like Counter
, ).
●
json
: Provides functions for working with JSON data.
●
re
: Provides functions for working with regular expressions.