python tutorial - Python telephonic interview questions - learn python - python programming

python interview questions :241

String Equivalence/Comparison in Python?


testfile = "test.txt"
with open(testFile) as f:
    for line in f:
        line = line.rstrip()
        if "#*#*# ham" in line or "#*#*# spam" in line: 
            print line

Another nice form is:

if any(substr in line for substr in (#*#*# ham", "#*#*# spam")):
    print line

python interview questions :242

MySQL database: lua or python

  • Mysql is a database server -- it doesn't have a menu. I think you mean mysql workbench which is a visual database design tool. That option allows you to use lua scripting or python scripting to help you on the design of your database -- it is unrelated to what happens on the mysql server

Learn python - python tutorial - microsoft-visual-studio - python examples - python programs

python interview questions :243

Write a Reg Expression that confirms an email id using the python reg expression module <Re>?

  • Python has a regular expression module <re>.
  • Check out the <re> expression that can check the email id for .com and subdomain.
import re

python interview questions :244

What do you think is the output of the following code fragment? Is there any error in the code?

list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])
  • The result of the above lines of code is []. There won’t be any error like an IndexError.
  • You should know that trying to fetch a member from the list using an index that exceeds the member count (for example, attempting to access list[10] as given in the question) would yield an IndexError.

python interview questions :245

How to use yield - generator?

  • You want to define a function with a generator which can iterate the numbers, which are divisible by 7 within range(n).


def getNum(n,div):
    for i in range(n):
        if i % div == 0:
            yield i
RANGE = 50

print [n for n in getNum(RANGE, DIVIDER)]


[0, 7, 14, 21, 28, 35, 42, 49]

python interview questions :246

How are the functions help () and dir() different?

  • These are the two functions that are accessible from the Python Interpreter. These two functions are used for viewing a consolidated dump of built-in functions.
  • help() - it will display the documentation string. It is used to see the help related to modules, keywords, attributes, etc.
  • dir() - will display the defined symbols. Eg: >>>dir(str) - will only display the defined symbols.

python interview questions :247

Python File ending with .py~?

  • It's a backup file -- many editors save the previous version of your file under the same name with a ~ appended.

python interview questions :248

What style does PyCharm / IntelliJ use for Python docstrings ?

  • Those are the Sphinx style doc strings.
  • Python has some strong opinions about doc strings, see PEP257.

python interview questions :249

Tell whether a character is a combining diacritic mark?

  • Use the unicodedata module:
import unicodedata
if unicodedata.combining(u'a'):
    print "is combining character"
    print "is not combining"

python interview questions :250

Which cassandra python pacakge to be used?

  • Pycassa is an older python driver that is thrift based while python-driver is a newer CQL3 driver based on cassandra's binary protocol. Thrift isn't going away but it has become a legacy API in cassandra so my advice going forward is to use the newer python driver.

Learn python - python tutorial - python-packages - python examples - python programs

  • In the Twissandra example application with the DataStax python-driver to provide an overview of CRUD and using prepared statements etc.
  • As for cql I haven't had any experience with this one, but the homepage of the project says it all:
  • This driver has been deprecated. Please use python-driver instead

Related Searches to Python telephonic interview questions