We can use the inbuilt function str() to convert a number into a string. If you want an octal or hexadecimal representation, we can use the oct() or hex() inbuilt function.
Python Interview Questions
Because it is used to make the new function object and return them in runtime.
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.
The difference between list and tuple is that a list is mutable while tuple is not.
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. import smtplib # Calling SMTP s …
In the list, an element present at the 2nd index from the right is 3. So, the output will be 3.
The output will be [‘!!Welcome!! ‘, ‘!!Welcome!!’]
Since indexing starts from zero, an element present at 3rd index is 7. So, the output is 7.
The enumerate() function is used to iterate through the sequence and retrieve the index position and its corresponding value at the same time. For i,v in enumerate([‘Python’,’Java’,’C++’]): print(i,v) 0 Python 1 Java 2 C++ # enumerate using an index sequence for count, item in enumerate([‘Python’,’Java’,’C++’], 10):
The shortest way to open a text file is by using “with” command in the following manner: with open(“file-name”, “r”) as fp: fileData = fp.read() #to print the contents of the file print(fileData)