A Python F-String Feature Most People Don't Know

Sdílet
Vložit
  • čas přidán 5. 09. 2024

Komentáře • 33

  • @Richard_de_Jong35
    @Richard_de_Jong35 Před rokem +5

    Great! It also works with format specification, e.g. print(f'{value = :.3f}')

  • @chalkypj
    @chalkypj Před rokem +2

    Fantastic, thank you. I never knew this. I learn something new from you almost every video. As a beginner I can already see this making my debugging so much better and easier.

  • @Zirescu
    @Zirescu Před 11 měsíci +3

    There should be caveat that this should only be used for quick debugging. Otherwise, you're in for a world of hurt. Logging is what should be used for debugging as it can disable it with a single change.

  • @mohsenhaddadi1117
    @mohsenhaddadi1117 Před rokem +2

    This equal feature is added and works from version 3.8

  • @ngneerin
    @ngneerin Před 11 měsíci +1

    I did a lot of print("response", reponse). Now on I could do print(f"{response = }")

  • @clementihammock7572
    @clementihammock7572 Před rokem +8

    Thumb up for more F string tips, and thanks.

  • @gedtoon6451
    @gedtoon6451 Před 6 měsíci

    If you create an object, my_object, from your own class, and try to print it with print(f"{my_object = }") you may not see what you expect. For it to work properly your class MUST implement __repr__. It will not work if you only implement __str__

  • @thomasgoodwin2648
    @thomasgoodwin2648 Před rokem

    That's awesome. Didn't know, but it should save key and eye strokes writing str n repr functions. Great for for debugging too. Smarter way of doing it especially if your tracking a lot of text output.
    🖖😎👍
    p.s. I'm not going back to rewrite all of those I wrote naively, but I might clean a few up as I go along. 😉

  • @rahuljamba5846
    @rahuljamba5846 Před rokem

    Great Man , Thank for sharing your knowledge !!!

  • @nicoventer5565
    @nicoventer5565 Před rokem

    Nice tip Fanks!!

  • @danno-h
    @danno-h Před 11 měsíci

    Love your work mate. Great tip

  • @thomasklose1969
    @thomasklose1969 Před rokem

    Very good! Keep going with your channel

  • @manfreddieterle1563
    @manfreddieterle1563 Před rokem

    thanks for this video, this is really helpful!

  • @asagiai4965
    @asagiai4965 Před 11 měsíci

    Interesting thing to know but I kind of don't recommend it for debugging.
    also it is not working for me. Maybe there's more to this than just putting those equal sign

  • @lesgrossman1965
    @lesgrossman1965 Před rokem

    thank you man!

  • @DeltaXML_Ltd
    @DeltaXML_Ltd Před rokem

    Great tips. Great content!

  • @willlywillly
    @willlywillly Před rokem

    Great video. Thank you!

  • @Little-bird-told-me
    @Little-bird-told-me Před rokem

    Good job !

  • @devabdul
    @devabdul Před 11 měsíci

    If you want print string anything like -+_()/\{}[]=*&#$% operators. Backslash etc, aur if you fetch string from internet and you don't know what is inside that string,
    For example
    myText = r"\{}[]=&#$%_-+()/*, myDer()"
    The output will be some what is inside myText
    r"value, method, etc literally anything"
    r is a Raw String, it will print as it

  • @piotrmazgaj
    @piotrmazgaj Před rokem

    Good tip.

  • @chyldstudios
    @chyldstudios Před rokem +1

    Nice!

  • @jvsonyt
    @jvsonyt Před rokem

    This is huge!

  • @TomanovicsGergely
    @TomanovicsGergely Před rokem

    Is this a feature of some later Python release?
    I use 3.6.9 and got a syntax error when tried it out.

  • @MattDvc
    @MattDvc Před rokem

    How I never knew about it. So useful

  • @RidingWithGerdas
    @RidingWithGerdas Před rokem

    This is cool. Thanks.

  • @rob.granger
    @rob.granger Před 11 měsíci

    nice!

  • @juancamacho479
    @juancamacho479 Před rokem

    most people dont know this in python? thats like a must in javascript xd

  • @rons96
    @rons96 Před rokem

    my hero.

  • @pepperpops6312
    @pepperpops6312 Před rokem

    very useful

  • @hbrokenheartm2892
    @hbrokenheartm2892 Před rokem

    so good

  • @timoteoqueiroz1627
    @timoteoqueiroz1627 Před rokem

    WHAT THE F IS THIS IN STRINGS? ...could've been an alternative thumb description😅

  • @jacobsoby3910
    @jacobsoby3910 Před rokem

    Nooooo... Please don't encourage the use of the f'string ... it's almost as bad a the programming language bf. (ref. en.wikipedia.org/wiki/Brainfuck)