0% found this document useful (0 votes)
31 views4 pages

FUNCTIO

Uploaded by

mannandemon123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views4 pages

FUNCTIO

Uploaded by

mannandemon123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

‭1.

Keywords‬

‭ ython has‬‭36 reserved keywords‬‭that 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.‬

‭2. Built-In Functions‬


‭There are over‬‭70 built‬‭-‭i‬n‬‭functions‬‭in Python. Here’s an extended list:‬

‭A. Input/Output Functions‬

‭●‬ ‭
print()‬
‭: Outputs text or variables.‬
‭●‬ ‭
input()‬
‭: Reads user input.‬
‭●‬ ‭
open()‬
‭: Opens a file and returns a file object.‬

‭B. Type Conversion Functions‬

‭●‬ ‭
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.‬

‭C. Mathematical Functions‬

‭●‬ ‭
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.‬

‭D. String Functions‬

‭●‬ ‭
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.‬

‭E. List and Sequence Functions‬

‭●‬ ‭
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.‬

‭F. Dictionary Functions‬

‭●‬ ‭
keys()‬
‭: Returns keys of a dictionary.‬
‭●‬ ‭
values()‬
‭: Returns values of a dictionary.‬
‭●‬ ‭
items()‬
‭: Returns key-value pairs.‬

‭G. Iteration Functions‬

‭●‬ ‭
range()‬
‭: Generates a sequence of numbers.‬
‭●‬ ‭
iter()‬
‭: Returns an iterator.‬
‭●‬ ‭
next()‬
‭: Fetches the next item from an iterator.‬

‭H. Functional Programming Functions‬

‭●‬ ‭
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()‬ True‬‭if any element is‬‭
‭: Returns‬‭ True‬
‭.‬
‭●‬ ‭
all()‬ True‬‭if all elements are‬‭
‭: Returns‬‭ True‬
‭.‬

‭I. Object and Type Functions‬

‭●‬ ‭
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.‬

‭J. File Handling‬

‭●‬ ‭
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.‬

‭3. Exception Handling‬

‭These keywords and functions help manage errors and exceptions:‬

‭●‬ ‭
try‬ except‬
‭,‬‭ finally‬
‭,‬‭ ‭: Handles exceptions.‬
‭●‬ ‭
raise‬
‭: Manually raises an exception.‬
‭●‬ ‭
assert‬
‭: Debugging aid that raises an error if condition is false.‬

‭4. Modules and Libraries‬

‭ 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.‬

You might also like