Interview :: python
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.
The shortest way to open a text file is by using "with" command in the following manner:
The enumerate() function is used to iterate through the sequence and retrieve the index position and its corresponding value at the same time.
Since indexing starts from zero, an element present at 3rd index is 7. So, the output is 7.
The output will be ['!!Welcome!! ', '!!Welcome!!']
In the list, an element present at the 2nd index from the right is 3. So, the output will be 3.
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.
The difference between list and tuple is that a list is mutable while tuple is not.
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.
Because it is used to make the new function object and return them in runtime.