Python's f-strings! - Friday Minis 317

Поделиться
HTML-код
  • Опубликовано: 13 июл 2024
  • As of Python 3.6 (which, admittedly, is several years old), you can now do string substitutions with less effort! Instead of using .format() or the % operator, you can now just mention the required variables inline!
    = CREDITS =
    My appreciation extends to the creators of the following external assets that made this video possible:
    Blown Away by Kevin MacLeod (incompetech.com)
    Licensed under Creative Commons: By Attribution 3.0
    creativecommons.org/licenses/b...
    ISRC: USUAN1200100
    = 0612 TV =
    0612 TV, a sub-project of NERDfirst.net, is an educational RUclips channel. Started in 2008, we have now covered a wide range of topics, from areas such as Programming, Algorithms and Computing Theories, Computer Graphics, Photography, and Specialized Guides for using software such as FFMPEG, Deshaker, GIMP and more!
    Enjoy your stay, and don't hesitate to drop me a comment or a personal message to my inbox =) If you like my work, don't forget to subscribe!
    Like what you see? Buy me a coffee → www.nerdfirst.net/donate/
    0612 TV Official Writeup: nerdfirst.net/0612tv
    More about me: about.me/lcc0612
    Official Twitter: / 0612tv
    = NERDfirst =
    NERDfirst is a project allowing me to go above and beyond RUclips videos into areas like app and game development. It will also contain the official 0612 TV blog and other resources.
    Watch this space, and keep your eyes peeled on this channel for more updates! nerdfirst.net/
    -----
    Disclaimer: Please note that any information is provided on this channel in good faith, but I cannot guarantee 100% accuracy / correctness on all content. Contributors to this channel are not to be held responsible for any possible outcomes from your use of the information.

Комментарии • 11

  • @rasseru_sama2118
    @rasseru_sama2118 3 года назад

    Subscriber from Philippines

  • @jay-rathod-01
    @jay-rathod-01 3 года назад

    Bro that's cool tutorial and cool channel name.

    • @NERDfirst
      @NERDfirst  3 года назад

      Hello and thank you for your comment! Glad you liked the video =)

  • @rasseru_sama2118
    @rasseru_sama2118 3 года назад

    Keep it up dude 🥳🥳

    • @NERDfirst
      @NERDfirst  3 года назад

      Hello and thank you very much for your comment and support! Glad you like my work =)

  • @k.chriscaldwell4141
    @k.chriscaldwell4141 3 года назад +1

    Cool, and good to know. Good presentation. I'm still going to continue to use .format as I like to keep data/contents separate from presentation like CSS offers in Web development. _print( "Presentation and {}".format( "data/contents.") )_

    • @NERDfirst
      @NERDfirst  3 года назад +3

      Hello and thank you for your comment! Yeah for sure! I realized .format() allows you to construct your templates beforehand, store it in a variable then call .format() on it later as well, which is something I don't think you can do with this method. So .format() stays in our Python arsenal =)

  • @sashikiran9
    @sashikiran9 3 года назад

    Thank you for the content. Do you need to import any library to use f strings or is it inbuilt ?

    • @NERDfirst
      @NERDfirst  3 года назад +2

      Hello and thank you for your comment! This is in-built, no import required, as long as you're using Python 3.6 or newer.

  • @mamazu1995
    @mamazu1995 3 года назад

    Very good video explaining the topic. I think every programming language should have some form of string interpolation.
    But you also added a little mistake in the video. You said "You can put any statement in here". Examples for statements are: if statements or while statements. Those things don't have a value where on the other hand "expressions" like x*2 or list (comprehension) expressions have a value. It's a minor knit pick and it was obvious what what you meant but just wanted to get the terminology correct.

    • @NERDfirst
      @NERDfirst  3 года назад +1

      Hello and thank you for your comment! Very good point, yes. I suppose it'd be more accurate to say that all expressions can be represented in the f-strings. Luckily a lot of things in Python have one-liner representations - Ternary operators, comprehensions and lambdas come to mind.
      Also, thanks for introducing me to the term "string interpolation"! Would've been a lot less clunky than how I said it in the video =)