i
Python functionality and evolution
Installing Python (windows and Ubuntu)
IDLE (Integrated Development and Learning Environment)
Write the first python program and execute it
Keywords in Python
Identifiers in Python
Indentation in Python
Comments in Python
Multi-line Comments in Python
Getting user input
Python Function
Calling a function
Arguments in Function
Scope of Variables
Modules in Python
The PYTHON PATH-Variable
Python File Open
Python File Opening Modes
The file-Object-Attributes
Python File Close() Method
Python File Read/Write
Python File Position
Renaming and Deleting Files in Python
Python Directory Methods
File/Directory Methods
Exceptions in Python
The try-finally Clause
The argument of Exception
Raising Exceptions
Python Built-in Exceptions
Python OOPs Concepts
Python Classes/Objects
Creating Instance Objects
Accessing Attributes
Built-In Class Attributes
Garbage Collection
Python Inheritance
Overriding Methods
Method overriding
Data Hiding
Regular Expression
The match function
The search function
Match Object Methods & Description
Matching or Searching
Search or Replace
Regular Expression Modifiers / Option Flags
Grouping with Parentheses
Python Socket Programming
Python Socket Server
Python Socket Client
Send Data Between Clients
Python Socket or Server
Python Socket Clients
Points to ponder
Finally block along with a try block. The finally block is place to put any code that execute, whether try-block raised exception or not. The syntax of the try/finally statement is :
try:
You do operations here
Due to exception, this may skipped.
finally:
This would always execute
You can’t use else clause as well along with finally clause.
Example
Live Demo
You do not have permission to open file in writing mode, then this will produce following
Output:
Error: can't find file or read data
The same example can be written more cleanly:
Live Demo
When an exception is thrown in try/block, the execution immediately passes to final block. After all statements in the finally, block executed, the exception is raised again and handled in the except statements if present in next higher layer of try/except statement.
Don't miss out!