Python Practice Arguments List Methods Static Method

In this class, We discuss Python Practice Arguments List Methods Static Method.

For Complete YouTube Video: Click Here

The examples discussed in this class will help the reader to improve his coding skill.

The reader can easily crack the campus placement exams.

Please take our placement training course ultimately to attend for any service-based company recruitment.

Q1) 
Which of the following functions have valid signature?
def func(arg1,*arg2,*arg3):
    pass
def func1(arg1,arg2,arg3=20):
    pass
def func2(arg1=20,arg2,arg4=40):
    pass

In the above function signatures. The function func2 is wrong.

In python, first, we have to place non-default arguments followed by default arguments.

The non-default arguments are after default arguments. So function func2 is not an acceptable signature.

To know more about function arguments. Click here.

Q2)

What is the output displayed by the below code?
lis=[0,2,1,3,0]
val=0
while(len(lis)!=1):
    lis.pop(1)
    lis.remove(lis[0])
    lis.append(val+1)
    val+=1
print(lis)

In the above program, we used three methods from the list class.

The pop method will remove delete the value from the index position mentioned.

The remove method will delete the element from the list.

The append function will append the element at the end of the list.

For more details on the list of, methods click here.

The while loop will execute till the list contains a single element.

After execution, the element in the list is [4].

Q3)
What is the output displayed by the below program?
class trainee:
    __count=998
    sections=[1,2,3,4]
    def __init__(self,empname):
        self.empname=empname
        trainee.__count+=1
        self.empid=trainee.__count
    @staticmethod
    def creatclassroom():
        trainee.sections.append(trainee.__count//200)
    def checksection(self):
        if trainee.__count//200<=len(trainee.sections):
            return trainee.sections[self.empid//200-1]
        else:
            self.creatclassroom()
            return trainee.sections[-1]
traineeref1=trainee("jack")
traineeref2=trainee("kate")
print(traineeref1.empname+' is allocated class room'+str(traineeref1.checksection()))
print(traineeref2.empname+' is allocated class room'+str(traineeref2.checksection()))

In the above program, classroom numbers are given.

The student id is taken, and the student has to be assigned with a class.

Four classrooms are given numbers 1,2,3,4.

Each classroom is taking 200 students. Suppose the classroom is filled with 200 students. Then a new classroom is given.

The code to assign a new classroom is given by the static method.

To know more about the static method. Click here.

The code to identify classrooms using student id is written in the method check section.

The method check section is dividing the student id by 200 because each section has 200 students.

Suppose the student id is not belonging to any of the classrooms on the list. It is calling create a classroom to create a class.

Given below is the final output of the program.

jack is allocated class room5
kate is allocated class room5