Skip to content

Commit 5cc646c

Browse files
author
mushu
committed
Updated With_As and Added iamge dir
1 parent 581da4c commit 5cc646c

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

File renamed without changes.

With_As.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
## With As
22
```python
3-
With the "With" statement, you get better syntax and exceptions handling. The with statement simplifies exception handling by encapsulating common preparation and cleanup tasks.In addition, it will automatically close the file. The with statement provides a way for ensuring that a clean-up is always used.The lines after as can be used as an object to refer that.Without the with statement, we would write something like this:
3+
With the "With" statement, you get better syntax and exceptions handling.
4+
The with statement simplifies exception handling by encapsulating common preparation and cleanup tasks.
5+
In addition, it will automatically close the file.
6+
The with statement provides a way for ensuring that a clean-up is always used.
7+
The lines after as can be used as an object to refer that.Without the with statement,
8+
we would write something like this:
49

510
file = open("hello.txt")
611
data = file.read()
@@ -17,9 +22,11 @@ with open("hello.txt") as inFile: # Use file to refer to the file object
1722

1823
Here we did not write separate close statement as it is handled by with.
1924
```
20-
![Output](/WA1.png)
25+
![Output](/images/WA1.png)
26+
```
2127
Above is the file hello.txt
22-
![Code](/WA2.png)
28+
```
29+
![Code](/images/WA2.png)
2330
```python
2431
Thus we can see that when we use “with” statement there is no need of separate close statement.
2532
With more than one item, the context managers are processed as if multiple with statements were nested:
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)