Home / Interview / python :: General Questions

Interview :: python

41) How Python does Compile-time and Run-time code checking?

In Python, some amount of coding is done at compile time, but most of the checking such as type, name, etc. are postponed until code execution. Consequently, if the Python code references a user-defined function that does not exist, the code will compile successfully. The Python code will fail only with an exception when the code execution path does not exist.

42) What is the shortest method to open a text file and display its content?

The shortest way to open a text file is by using "with" command in the following manner:

43) What is the usage of enumerate () function in Python?

The enumerate() function is used to iterate through the sequence and retrieve the index position and its corresponding value at the same time.

44) Give the output of this example: A[3] if A=[1,4,6,7,9,66,4,94].

Since indexing starts from zero, an element present at 3rd index is 7. So, the output is 7.

45) What will be the output of ['!!Welcome!!']*2?

The output will be ['!!Welcome!! ', '!!Welcome!!']

46) What will be the output of data[-2] from the list data = [1,5,8,6,9,3,4]?

In the list, an element present at the 2nd index from the right is 3. So, the output will be 3.

47) How to send an email in Python Language?

To send an email, Python provides smtplib and email modules. Import these modules into the created mail script and send mail by authenticating a user.

It has a method SMTP(smtp-server, port). It requires two parameters to establish SMTP connection.

A simple example to send an email is given below.

It will send an email to the receiver after authenticating sender username and password.

48) What is the difference between list and tuple?

The difference between list and tuple is that a list is mutable while tuple is not.

49) What is lambda function in Python?

The anonymous function in python is a function that is defined without a name. The normal functions are defined using a keyword "def", whereas, the anonymous functions are defined using the lambda function. The anonymous functions are also called as lambda functions.

50) Why do lambda forms in Python not have the statements?

Because it is used to make the new function object and return them in runtime.