Class-Keyword

Wed 12 November 2025
#  created : 20250111
#  https://www.scientecheasy.com/2022/09/reserved-keywords-in-python.html/
#  class Keyword
#  example for a class declarstion 
class ClassExample:
    def func1(parameters):
        . . . .
    def func2(parameters):
        . . . .
with open('myfile.txt', 'w') as file:
    file.write('Hi jerin!')
#  as Keyword
import math as x
print(x.cos(0))
1.0
#  pass keyword
def func():
    pass
class A:
    pass
#  lambda Keyword
cube = lambda x: x * x * x
print(cube(7))
343
#  import Keyword
import math
print(math.sqrt(25))
5.0
#  from Keyword
from math import sqrt
print(sqrt(625))
25.0
#  del Keyword
my_var1 = 200
my_var2 = "Scientech Easy"
print(my_var1)
print(my_var2)
200
Scientech Easy
del my_var1
del my_var2
print(my_var1)
print(my_var2)
---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

Cell In[25], line 1
----> 1 print(my_var1)
      2 print(my_var2)


NameError: name 'my_var1' is not defined
# global Keyword
g_var = 50
def func_read():
    print(g_var)
def func_write():
    global g_var
    g_var = 100
func_read()
func_write()
func_read()
50
100
#  nonlocal Keyword
def outer_func():
    x = 50
    def inner_func():
        nonlocal x
        x = 100
        print("Inner function: ",x)
    inner_func()
    print("Outer function: ",x)
outer_func()
Inner function:  100
Outer function:  100
def outer_func():
    x = 50
    def inner_func():
        x = 100
        print("Inner function: ",x)
    inner_func()
    print("Outer function: ",x)
outer_func()
Inner function:  100
Outer function:  50


Score: 30

Category: python-basics