in Education by
There are two codes, what are the difference between them: Using type import types if type(q) is types.DictType: do_something() if type(w) in types.StringTypes: do_something_else() Using isinstance() if isinstance(q, dict): do_something() if isinstance(w, str) or isinstance(w, unicode): do_something_else() Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can use isinstance() : if isinstance(w, (str, unicode)): do_something_else() alternatively, you can use basestring abstract class: if isinstance(w, basestring): do_something_else() Hope This Helps, Happy Learning.

Related questions

0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me the difference between a function decorated with @staticmethod and one with @classmethod? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I'm learning the Python programming language and I've come across something I don't fully understand. In a method ... know very much. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Is there any reason for a class declaration to inherit from an object? I just found some code that does this ... class code follows... Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How can I check a given object is of a given type? How can I check that a object inherit a given type? There's ... that it's a string? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have a python variable how can I see that it's unsigned 32 bit or signed 16 bit, etc? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a easy method to check if a variable is a dictionary, list or anything else? I want to know ... is of which type. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me the difference between _str_ and _repr_ in python? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    What is the meaning of using leading underscores before the name of an object in Python? And what's the difference ... , method, etc.? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    In Python What command can I use to find these: Location of file which I am executing, and Current directory ( ... script in Python) Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can I generate a string of size N. I want it to be of uppercase English letters and numbers like this: 7I2D86 ... do it in Python. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me the basic difference between @classmethod and @staticmmethod, I am good with C++ so you ... we use them? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    What * and ** do for param2 in the following: def foo(param1, *param2): def bar(param1, **param2): Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Is there a built-in that removes duplicates from a list in Python, whilst preserving order? I know that I can ... idiom if possible. Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I want to write a program which returns different values for different input,it can be easily done using switch ... some alternative? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
...