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 8918395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:44:29+00:00 2026-06-15T05:44:29+00:00

As far as I know, Python doesn’t support function overloading, but in Python documentation

  • 0

As far as I know, Python doesn’t support function overloading, but in Python documentation

link to py3k doc

seems that there are 2 different str methods, str(object='') and str(object=b'', encoding='utf-8', errors='strict')

How are defined these functions? When is the first invoked and when the second?

Can I create my own f(o='') and f(o=b'') functions (makes sense)?

UPDATE

Output for str(b'abc','utf-8') is abc but

output for str(b'abc') is b'abc'

  • 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-06-15T05:44:30+00:00Added an answer on June 15, 2026 at 5:44 am

    No, python doesn’t support overloading because it doesn’t need to. Python documentation often shows different ways of calling a method to illustrate different uses, but there is only one str() callable (a type in this case).

    In this case, str() accepts multiple keyword arguments, which have default values if not specified. The str() type then uses the those extra keyword arguments, if specified, to interpret a b'' byte string argument. If no keyword arguments were passed in, str() behaves differently.

    In other words, str() adjusts it’s behaviour based on wether or not the keyword arguments have been supplied. If that is the case and the first argument is a bytestring or bytearray, it’ll decode that argument to unicode text, using the extra keyword arguments to control the decoding process.

    You can define your own function that’ll behave the same way as regards to the keyword arguments, checking the type of the first argument:

    def f(o, encoding=None, errors=None):
        if encoding is None and errors is None:
            return o.__str__()
    
        if isinstance(o, str):
            raise TypeError('decoding str is not supported')
    
        if not isinstance(o, (bytes, bytesarray)):
            raise TypeError('coercing to str: need bytes, bytearray'
                 'or buffer-like object, %s found' % type(o).__name__)
        return o.decode(encoding, errors)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that Tortoise HG (the windows explorer Mercurial plugin) uses Python internally, but
So far I know that FileSystemWatcher can look into a folder and if any
As far as I know, C2DM is per app per device thing..but my question
As far as I know that JSF keeps all the session scoped bean in
as far as i know there are cross domain restictions that wont allow you
There are several major unit tests frameworks, but as far as I know all
Just curious. I may be wrong, but as far as I know, most languages
I'm looking for a Python caching library but can't find anything so far. I
I'm trying to make a linked list class in python (pointless I know, but
As far as know, I must be careful with PHP, and I think Javascript.

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.