Worksheetsبرمجة موجهة
Total questions: 67
Worksheet time: 34mins
defines an in-built module platform that provides system information.
Python
Platform module
is used to retrieve as much possible information about the platform on which the program is being currently executed.
Python
Platform module
Purpose: Returns a string with a detailed description of the platform.
platform.platform()
platform.machine()
platform.processor()
platform.system()
Description: This function gives you a complete summary of the platform you are running on, which includes information like OS name, release, version, and additional identifiers.
platform.platform()
platform.processor()
platform.processor()
platform.system()
Purpose: Returns the machine type (architecture).
platform.platform()
platform.machine()
platform.processor()
platform.system()
Description: This provides the hardware identifier of the machine, such as x86_64 for 64-bit Intel processors, arm for ARM-based systems, etc.
platform.platform()
platform.machine()
platform.processor()
platform.system()
Purpose: Returns the name of the processor.
platform.platform()
platform.machine()
platform.processor()
platform.system()
Description: This function returns the processor type of the machine you are working on. If the information is not available, it may return an empty string.
platform.platform()
platform.machine()
platform.processor()
platform.system()
Purpose: Returns the name of the operating system.
platform.platform()
platform.machine()
platform.processor()
platform.system()
Description: This function provides a simple way to check the underlying OS. The output might be Windows, Linux, Darwin (for macOS), etc.
platform.machine()
platform.machine()
platform.processor()
platform.system()
Returns the version of the operating system.
platform.version()
platform.python_implementation()
platform.python_version_tuple()
Description: This function returns the version information of the current operating system.
platform.version()
platform.python_implementation()
platform.python_version_tuple()
Purpose: Returns the name of the Python implementation.
platform.version()
platform.python_implementation()
platform.python_version_tuple()
Description: This function tells you which Python interpreter is being used, such as CPython, PyPy, IronPython, etc
platform.version()
platform.python_implementation()
platform.python_version_tuple()
Purpose: Returns the Python version as a tuple.
platform.version()
platform.python_implementation()
platform.python_version_tuple()
Description: This function returns the current version of Python as a tuple, which is useful when you want to split the major, minor, and patch versions
platform.version()
platform.python_implementation()
platform.python_version_tuple()
This function returns a tuple that stores information regarding the system.
platform.uname()
platform.python_build()
platform.architecture()
this function can be used to replace the individual functions to retrieve information about the system, node, release, version, machine, version and processor. Thus, a single function serving many purposes
platform.uname()
platform.python_build()
platform.architecture()
This function returns a tuple that stores information about the python build date and build no. This information is stored in the tuple as a string datatype.
platform.uname()
platform.python_build()
platform.architecture()
This function returns a tuple that stores information about the bit architecture(number of bits in the platform processor) and linkage format( defines how names can or can not refer to the same entity throughout the whole program or one single translation unit).
platform.uname()
platform.python_build()
platform.architecture()
(like OS, hardware, and processor)
system environment
Python runtime itself
(like version and implementation)
system environment
Python runtime itself
are a fundamental aspect of Python programming that handle errors in code, preventing programs from crashing unexpectedly.
Exceptions
ValueError
IndexError
FileNotFoundError
Raised when a file operation fails, such as trying to open a file that doesn’t exist.
exception
ValueError
IndexError
FileNotFoundError
is an event that occurs during the execution of a program and disrupts the normal flow of instructions.
exception
ValueError
IndexError
FileNotFoundError
Raised when trying to access an index that is not within the range of a list or other data structure.
exceptions
ValueError
IndexError
FileNotFoundError
are a type of error that occurs when a syntactically correct program runs into an unexpected situation.
exceptions
ValueError
IndexError
FileNotFoundError
Raised when a function receives an argument of the right type but an inappropriate value.
exceptions
ValueError
IndexError
FileNotFoundError
In this case, when Python encounters the division by zero, it does not crash. Instead, it catches the error and executes the code in the except block, printing the error message.
try-except Block
Multiple Exceptions
else Block
finally block
is used to specify code that should run no matter what happens, whether an exception is raised or not.
try-except Block
Multiple Exceptions
else block
finally block
This is useful for cleanup operations, such as closing files or releasing resources.
try-except Block
Multiple Exceptions
else Block
finally Block
This is useful in situations where you need to guarantee that certain cleanup code runs, such as closing a file or a database connection.
try-except Block
Multiple Exceptions
else Block
finally Block
This is useful when different exceptions should be handled similarly.
try-except Block
Multiple Exceptions
else Block
finally Block
is executed if the try block does not raise an exception.
try-except Block
Multiple Exceptions
else Block
finally Block
used to handle the normal case where no exceptions occur.
try-except Block
else block
Multiple Exceptions
finally Block
helps in separating the error handling code from the normal operation of the program.
try-except Block
Multiple Exceptions
else Block
finally Block
This allows for more granular control over how exceptions are handled, particularly in cases where some errors should be handled differently depending on the context.
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
allows you to define your own exceptions by creating a new class that inherits from the built-in Exception class.
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
This can be useful in specific cases where you want to handle errors more granularly
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
perform some actions, and then re-raise the exception so it can be handled elsewhere.
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
is raised inside a function and is not caught, it propagates upwards to the calling function.
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
This process continues until the exception is caught or until it reaches the top of the call stack, at which point the program crashes.
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
if an exception occurs in divide, it will propagate up to get_input, and if get_input doesn’t handle it, it will propagate to the main code block.
Nested try-except Blocks
Exception Propagation
Reraising Exceptions
Custom Exceptions
128 basic characters, including letters, numbers, and symbols.
ASCII
Unicode
UTF-8
Codepoints
is historically crucial as it laid the foundation for later encoding standards.
ASCII
Unicode
UTF-8
Codepoints
Represents thousands of characters across languages,each with a unique hexadecimal code point.
ASCII
Unicode
UTF-8
Codepoints
allows representing thousands of characters from various languages and symbol.
ASCII
Unicode
UTF-8
Codepoints
represent unique Unicode values.
ASCII
Unicode
UTF-8
Codepoints
balancing storage efficiency with the ability to represent diverse characters.
ASCII
Unicode
UTF-8
Codepoints
A popular Unicode encoding that uses 1-4 bytes per character, efficient for global text.
ASCII
Unicode
UTF-8
Codepoints
allow using special characters in strings.
Escape Sequences
Ord()
Chr()
Include special characters in strings, like ‘\n’ for newline or ‘\t’ for tab.
Escape Sequence
Ord()
Chr()
converts a single character to its Unicode code as an integer
Escape Sequence
Ord()
Chr()
Gets Unicode codepoint of a character.
Escape Sequence
Ord()
Chr()
Gets character from a Unicode codepoint.
Escape Sequence
Ord()
Chr()
it is converts an integer codepoint to its corresponding character.
Escape Sequences
Ord()
Chr()
are defined with single (‘) or double (“) quotes. Multi-line strings use triple quotes (‘’’ ‘’’ ) and preserve formatting, ideal for documentation and formatted text.
Literals
Indexing
string in Python are ordered
Literals
Indexing
Strings are ordered, starting from index 0; negative indices access from the end.
Literals
Indexing
allows extracting substrings using start and end indices, with the end index exclusive.
Slicing
Immutability
Iteration
Looping through strings can use enumerate for index and character, or list comprehensions for transformations.
Slicing
Immutability
Iteration
they cannot be altered after creation.
Slicing
Immutability
Using enumerate with a for loop gives both index and character.
Enumerate
For Loop Iteration
Comprehension
Checks on each character, maintaining readability.
Enumerate
For Loop Iteration
Comprehensions
each character in a string can be accessed individually using a for loop.
Enumerate
For Loop Iteration
Comprehensions
to handling text data is foundational for programming
Python’s approach
strings
are essential for almost every type of application, from data processing to user interactions
Python’s approach
strings
