Nama: Prado Pratama Putra NIM: 09030581923047 Kelas: Tk4A
Nama: Prado Pratama Putra NIM: 09030581923047 Kelas: Tk4A
Except zerodevisionError:
print(unknowv-var)
Finally :
Print(“this is excused last”)
RAISING EXEPTION
You can exceptions by using the raise statement .
Example :
Print (1)
raise valueError
print(2)
Exceptions can be raised with arguments that give detail about them
Name = “123”
raise nameError (“invali name!”)
In except blocks , the raise statement can be used without
arguments to re –raise whatever
Exception occured
ASSERTION
An assertion is a sanity-check that you can turn on or turn of
when you have finished testing the program.
an axpression is tested, and if the result comes up false, an
exception is raised
Assertions are carried out through use of the assert
statement .
Print(1)
assert 2+2 =4
Print(2)
Assert 1+1=3
Print (3)
Opening files
You can use python to read and write the contents of
files text files are easiest to manipulate ,bepore a file
can be edited , it must be opened,using the open
function
You can specify the mode