An interesting python function I just made. Probably not the first to do so.

def printf(fmt, *args):
print(fmt, args, end="")

  • 2
    What does it do?
  • 1
    @sid-maddy Probably, I'm no professional. Why is it more correct?
  • 1


    printf("{0}",27); //python(3)

    am i clear enough?
  • 1
    @shelladdicted My function was written in python 3... And why did you add semicolons?
  • 1
    @AlgoRythm ok, so I was not clear enough.

    1)python3 allows semicolons so it's not a SyntaxError.

    2)your function doesn't support text format (%d,%.1f in C/C++) that in python3 are replaced by {0}
    the function that @sid-maddy provied supports that so it's a bit better.

    i wrote python(3) because in python2 {0} is replaced by %
  • 1

    1) Just because a language allows it doesn't mean you should do it. You shouldn't.

    2) (see attached)
  • 3

    3) comments in python are # not //
  • 1
    @AlgoRythm i just saw the screenshot in python(3) use {0} instead of %d etc....

    see docs for format of strings.

    printf("Hello {0}!",name); #// yes i use ; and // ;-) (joking)

    #another way
    text = "hello {0}".format(name);
  • 2
    @shelladdicted Yeah, still not sure what you're going at, but whatever. I understand string formatting. The % operator works in both 2 and 3 and works with tuples and shit too.
Add Comment