Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:54:31+00:00 2026-05-15T14:54:31+00:00

So I hope this is a valid question… I’ve recently (today actually) decided to

  • 0

So I hope this is a valid question… I’ve recently (today actually) decided to learn how a scripting language, so I chose Python. While glancing over code, I felt overwhelmed, and I soon realized that the reason was that I didn’t know what data type conversions and stuff were going on.

My question is: Is there any convention of keeping track of what the data type is? I come from more of a C background, so I find this quite confusing. Any tips?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:54:32+00:00Added an answer on May 15, 2026 at 2:54 pm

    The normal Python approach is duck typing — from the old phrase “if it quacks like a duck, and walks like a duck, it’s duck enough for me”.

    In exceptional cases where you really must check what type something is (to do different things to otherwise similar types… usually not a good idea), that’s what isinstance is for.

    isinstance used to be considered a last-ditch measure, with serious warnings against overusing it… but while the gist of that classic tirade remains valid, since Python 2.6 it has acquired an important proviso: while checking if something is an instance of a specific concrete class remains in the “rarely a good idea” category, checking if it’s an instance of an abstract base class (aka ABC) is a more frequently useful idea, because it just offers a nice and flexible way to check if something implements or not some interface.

    For example, to check if an object is callable, one used to have to do something like:

    if hasattr(type(obj), '__call__'): ...
    

    Since 2.6, the preferred alternative has become:

    import collections
    if isinstance(obj, collections.Callable): ...
    

    much more direct and cleaner. Richer ABCs such as, e.g., collections.MutableSequence, which imply the existence and coordination of many different methods, make this exponentially stronger.

    The fact that checking (with isinstance) the membership in a concrete type is not so good, while checking the membership in an ABC is more often useful, lies in a principle that the “Gang of 4” expressed clearly and intensely in the first part of their wonderful book “Design Patterns” (in a mostly C++ context, but it really applies much more widely than that!): program to an interface, not to an implementation.

    Checking membership of a concrete class indicates you’re probably guilty of programming to an implementation; with an ABC, you’re basically checking an interface, so many issues just aren’t big problems any more (ABCs are more than just interfaces — they can also offer “implementation help” to their concrete subclasses — but, when we’re talking about isinstance, thinking of them as interfaces is probably the most helpful stance).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I hope this is a valid question) As I stated in my title, I'm
I hope this is a valid question: how does intellisense work in VS2008? I'm
Hope this question is not stupid since I am an amateur web designer. I
hope this will be a quick easy question, I've just tried my app on
I hope this question isn't too general. Well, the situation is that I am
I hope this question isn't too dumb. We have many websites internally that need
I hope this question takes a simple fix, and I am just missing something
Hope this is the right place to be asking this, so my apologies if
Hope this is not a dupe. I would like to be able to do
Hope this isn't a waste of your time. I'm working on a project, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.