Class-Keyword

Tue 09 December 2025
#  class Keyword
#  example for a class declarstion 
class ClassExample:
    def func1(parameters):
        . . . .
    def func2(parameters):
        . . . .
  Cell In[3], line 3
    . . . .
    ^
SyntaxError: invalid syntax
class ClassExample:
    def func1(parameters):

    def func2(parameters):
  Cell In[4], line 4
    def func2(parameters):
    ^
IndentationError: expected an indented block after function definition on line 2
with open('myfile.txt', 'w') as file:
    file.write('Hi Meeran')
#  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)
200
print(my_var2)
Scientech Easy
del my_var1
del my_var2
print(my_var1)
---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

Cell In[27], line 1
----> 1 print(my_var1)


NameError: name 'my_var1' is not defined
print(my_var2)
---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

Cell In[28], line 1
----> 1 print(my_var2)


NameError: name 'my_var2' 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

outer_func()
Inner function:  100
Outer function:  50


Score: 35

Category: Python basics