No video

F-strings In Python: Everything You Need To Know

  Рет қаралды 49,955

ArjanCodes

ArjanCodes

Күн бұрын

Пікірлер: 237
@ArjanCodes
@ArjanCodes 11 ай бұрын
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis.
@carecavoador
@carecavoador 2 жыл бұрын
Oh, yes. My favorite dessert for fridays lunches: Arjan videos.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Enjoy :)
@OMGnotThatGuy
@OMGnotThatGuy 2 жыл бұрын
For sure. Best Python videos on KZbin!
@carecavoador
@carecavoador 2 жыл бұрын
@@OMGnotThatGuy I really enjoy how he puts valuable knowledge on his videos. Even simple things like f strings can be really rich subjects while being pleasing to watch. Today I learned a lot o things I didn't know, for example.
@OMGnotThatGuy
@OMGnotThatGuy 2 жыл бұрын
Great video! Maybe I missed it, but did Arjan mention using using braces inside braces for variables like number of spaces to use in alignments? >>> list_of_words = ['a','bc','def'] 2 just = len(max(list_of_words)) 3 for word in list_of_words: 4 print(f"This word: {word:>{just}}") This word: a This word: bc This word: def
@guyindisguise
@guyindisguise 2 жыл бұрын
Thanks! He didn't mention that and I've been looking for to do that a while ago.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Great tip, thanks!
@lukajeliciclux3074
@lukajeliciclux3074 2 жыл бұрын
There is only one case where Template strings are preferable over F-strings. While you are working with databases and sql queries f-strings could be easily injectable by sql injection attacks. Template strings can’t be injected.
@Tweakimp
@Tweakimp 2 жыл бұрын
One reason to use % templates is in logging functions: The logger can skip the variable evaluation if the logging is skipped. This would not work with fstrings. Also you can not put backslashes in fstrings. f"{' '*3}" raises a SyntaxError
@notead
@notead 2 жыл бұрын
You can totally put backslashes inside f-strings, just not within the brackets.
@nigh_anxiety
@nigh_anxiety 2 жыл бұрын
the backslash can't be within the braces of the f-string expression, but you can include a string which contained a backslash escaped character. `x = ' '; print(f"{x*3} ")` is completely fine.
@Tweakimp
@Tweakimp 2 жыл бұрын
@@nigh_anxiety Thanks :)
@meliodas4560
@meliodas4560 2 жыл бұрын
I watch Arjan in the morning with my coffee. He just has such a pleasant, relaxing voice. I don't often write anything large in Python anymore, but I use Python extensively in security tasks... these videos are always informative and contain little bits of info that are often overlooked. Arjan, I would watch a video on Pendulum in a heartbeat!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thank you, glad you liked the video!
@Amstelchen
@Amstelchen 2 жыл бұрын
07:35 It's a circumflex. In German, it is sometimes called "Dach" or more collquially, "Dacherl" which means "little roof" ^^
@illiterate467
@illiterate467 2 жыл бұрын
That's a new word for me. Very cool. Alternatively, the ^ symbol is also called a "caret", which is what I've always called it and I think is probably the most common term in English (US).
@ChongFrisbee
@ChongFrisbee 2 жыл бұрын
Circumflex is a diacritic, meaning it is used to describe situations where other characters are modified, like ê for example. The isolated character is called caret
@raphajptube
@raphajptube 2 жыл бұрын
f-strings cannot be used for creating templates. The code bellow would throw a NameError as 'number' is not defined. However it works with .formating. template = "my number is {number}" for i in range(5): print(template.format(number=i)
@user-hf5be1zu7s
@user-hf5be1zu7s 2 жыл бұрын
format() is useful in formatting string variables, which can't be done with f-strings. In some cases, I store frequently-used strings in my code as constant to prevent hard-coding. I use format() to format variables into the string constant. for example: STRING = "Hello, {}" print(STRING.format("Sara")) output: Hello, Sara
@K1assh
@K1assh 2 жыл бұрын
Weird, but thanks for the example. Could come in handy. It's backwards to how I always use format(), which is an interesting way to think about it.
@parswarr
@parswarr 2 жыл бұрын
Yep, same. For really big string templates I'll even use the jinja template generator on rare occasion.
@alexvv2053
@alexvv2053 2 жыл бұрын
I had to look it up: the 'little roof' is called a caret in programming
@nathanbrown2640
@nathanbrown2640 2 жыл бұрын
I was going say, yes, ^ tends to get called 'caret' in English, at least in my experience here in the UK. Sometimes we might say 'circumflex', referring more to when it is a diacritic, especially in French (which is where I think many English speakers tend to meet it first)
@clasdauskas
@clasdauskas 2 жыл бұрын
aka 'hat' - now I want to know what the actual Dutch is.
@jeancerrien3016
@jeancerrien3016 2 жыл бұрын
Thank you for the video. Seems worth mentioning: if your class implements __format__, then f"{var:str}" equals format(var "str"). In particular, the documentation for string.format and datetime.datetime.format may help explain many of the examples presented here.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thank you Jean, glad you liked the video!
@eliavrad2845
@eliavrad2845 2 жыл бұрын
4:00 Number literals ignore underscores*, so it's common to use f"(44_000_000_000:,.2}" instead of counting zeros. * things like 1_23_4.56_7 are allowed (if ugly), but leading and trailing underscores are forbidden from both sides of the decimal point, so _100, 3.14_, 9_.8, and 2._6 all throw Syntax Error
@LordDoucheBags
@LordDoucheBags 2 жыл бұрын
Easier to just use 44e9 as a float, then convert to int as you need to 🤷‍♂️
@PhyFlame
@PhyFlame 2 жыл бұрын
If I remember it correctly str_format will be outperforming any other formatting once there are a lot of variables called. I believe in Python 3.9 that would have been a string printing out 13 different variables. For me this would be a very artificial case, but also the one aspect which speaks in favour of str_format. Also all the lovely features of f-strings were covered, which delights me. Good job on that :)
@agb2557
@agb2557 2 жыл бұрын
As always I love your videos, the only thing I’d prefer is if you could leave the example output on screen for one second or so longer, eg: datetime formatting section
@erikchubb9704
@erikchubb9704 2 жыл бұрын
When I need to study the code or output, I just hit spacebar (which pauses the video). If i don't need to see it, then the current editing style keeps things moving fast. So my preference is to stick with the current editing style
@pamdemonia
@pamdemonia 2 жыл бұрын
Really love your videos! Interesting, fast, and useful. Plus the perfect length. Thanks so much for this.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad the content is helpful!
@WillyJL
@WillyJL Жыл бұрын
20:30 you can also use the multiline strings with fstring formatting, same as usual (3 quotes at beginning and end, with f before): sentence = f"""some multiline text"""
@equu497
@equu497 Жыл бұрын
I wasn't sure how you were gonna talk about f-strings for 20 minutes, but you made me realize how much I don't know, and every minute count. Amazing video as always Arjan
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful!
@dalicodes
@dalicodes 2 жыл бұрын
Thank you Arjan. I have been using F-string for sometime now but didn't know how robust I could use them like you did in this video. In my most recent uploaded video I created a class for polynomial mathematical functions and F-string helped a lot in the development of the __str__ method.
@hammerheadcorvette4
@hammerheadcorvette4 Жыл бұрын
My first encounter with f'strings, I needed to mimic real world address data for a project. So creating a a variable with random.choice() or random.random() all the way through was fun. A names list for the street names, people name, and city names, a random number for street address and building or house number, random choice of apt/suite number, random zipcode etc. All in one fstring.
@vk3fbab
@vk3fbab 2 жыл бұрын
Great video. The only thing you missed that I use all of the time is the triple quote multi line string. Using that you can use single and double quotes in your string to access dicts. Glad you skipped the most newbie form of string generation the evil and slow + operator. I saw a cheat sheet for python and it showed that, I thought whomever wrote that cheat sheet mustn't have used python much. I use and peach the use of f strings for all the reasons you mentioned. So readable and obvious.
@virtualraider
@virtualraider 2 жыл бұрын
Ah, I didn't see your comment before I replied with the same thing 😅
@Daviid_5
@Daviid_5 2 жыл бұрын
I read that repr should always return a string that, when pasted on the python interpreter, allows you to create an exact copy of the object
@biermeester
@biermeester 2 жыл бұрын
The __repr__ method should also return a unique string for each object, even when they have the same value. That's why the memory address is included in the output of the default __repr__ method.
@DrGreenGiant
@DrGreenGiant 2 жыл бұрын
^ is called a "caret" or a "hat" if on top of a character, in English. Thanks for the great videos
@Warclimb64
@Warclimb64 Жыл бұрын
Thanks for this video! It's amazing to see a experienced programmer explaining in deph a concept that will considered for beginners.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you so much, glad you liked the video!
@twelvethis3979
@twelvethis3979 2 жыл бұрын
I'm a big fan of Arjan's videos because he is a strong proponent of simple and easy-to-read code. I wish we had a couple of Arjan clones at my company 😀
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad you liked the video and the content is helpful!
@jainicz
@jainicz 2 жыл бұрын
I have been using f-strings for almost everything except (1) Dynamic formatting. Declare an unformatted string such that it can later be used in multiple places, replaced with different variables. (2) LaTeX or any script that involves a lot of curly brackets, "{" and "}". While it is possible to escape curly brackets in f-strings, I would prefer to keep my script concise.
@MedievalChips
@MedievalChips 2 жыл бұрын
Thank you, Arjan. I 've been using f strings since they came out and i still learned a thing or two.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad you liked it!
@stevenwilson2292
@stevenwilson2292 2 жыл бұрын
Yes, do a video on pendulum please.
@rahulkmail
@rahulkmail 2 жыл бұрын
Excellent. There are lot of doubts cleared on "f-string" formatting.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Rahul, glad the content is helpful!
@leidem
@leidem 2 жыл бұрын
Thanks for the video! I've found one niche use case for the old `format` method, which was in dynamic configurations. If I want the user to be able to specify a string (such as a filename), they can specify it as "file-{}-23", say, and various dynamic metadata will then be inserted into the filename using the `format` method.
@virtualraider
@virtualraider 2 жыл бұрын
The only thing I haven't been able to figure out how to do with f-strings that you can do with .format is how to expand a dictionary into the placeholders. i.e. don't think you can do this: ``` template = "my number is {number} {item}" values = dict(number=1, item='box') print(template.format(**values)) ``` Output: _my number is 1 box_
@ArjanCodes
@ArjanCodes Жыл бұрын
That's a good reason indeed to still use templates. You could also do this, but templates might still be easier: ``` FRUITS = [{"name": "Arjan", "fruit": "apples"}, {"name": "Paula", "fruit": "grapes"}] for obj in FRUITS: name, fruit = obj.values() print(f"{name} likes {fruit}.") ```
@PaulSmith-zs5je
@PaulSmith-zs5je 2 жыл бұрын
This is a 1337 f string video.. Hat or Caret we call your little roof.. Keep up the great content.. Also something not mentioned in video is if you want to use an integer for the number of decimal places you need to use nested f-string formatting to achieve this.
@pikkusiili2490
@pikkusiili2490 2 жыл бұрын
Formatted strings are left-aligned by default so the extra spaces in f"{greet:6}" appear on the right (i.e., "Hi "). The ">" switches this to right-aligned (which is the default for numbers).
@nordgaren2358
@nordgaren2358 2 жыл бұрын
I have been using interpolated strings in C# since I discovered them. They are nice in python, too! I wish there was interpolated strings in C or C++, though!
@davidjnevin
@davidjnevin 2 жыл бұрын
Particularly liked the multi-line use. 👍👏
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much David.
@alexbigkid
@alexbigkid 2 жыл бұрын
@Arjan: love the f-strings. As you mentioned they were introduced in v3.6. However the f-string debugging version is valid from v3.8. My tox test were failing with 3.7. That is how I discovered. The reason why developers don’t use the new formatting is not to break backwards compatibility.
@renatopiacente5329
@renatopiacente5329 Жыл бұрын
Thank you very much for the content and valuable lesson. I'd really like to learn more about pendulum, will you create a class about it as well?
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks for the suggestions, Renato, I've put it on the list.
@K1assh
@K1assh 2 жыл бұрын
wow, what a great QOL update. I've been still using the function, which would always end up looking like .format(name=name, age=age, screw=this). Which hurts my heart. This new way uses all the same operators that I am used to, so easy and much appreciated change.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad the content is helpful!
@germanicus1475
@germanicus1475 2 жыл бұрын
I think you read my mind. This is exactly what I was looking for! Thank you!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful! :)
@Lou-mw8uv
@Lou-mw8uv Жыл бұрын
Thanks for explaining this so well. Cleared the 'fstring brain fog' I was in!
@ArjanCodes
@ArjanCodes Жыл бұрын
Glad it helped!
@jurgenrusch4041
@jurgenrusch4041 2 жыл бұрын
Hi Arjan, again a very nice and complete video. Great! I do have one question: I love f-strings but in loggers I seem only to be able to use % for lazy evaluation. Loggers do support {} bu that only seems to be possible in the specification of the log-message. So, question: can I use f-string style {} for lazy evaluation of log messages?
@silkogelman
@silkogelman 2 жыл бұрын
That debugging feature with the equal sign at 19:31 is going to save me time, thank you! I did not know we could apply Datetime in f-strings. Even math and assignment expressions! Awesome stuff. Pendulum looks interesting, Arrow comes to mind too.
@muthvar1
@muthvar1 Жыл бұрын
Is this debugging feature available in 3.6.8? I hit syntax issues in 3.6.8 when I try this
@polimorphic13
@polimorphic13 Жыл бұрын
@@muthvar1 I found this in other comment: " f-string debugging version is valid from v3.8".
@jefralston
@jefralston Жыл бұрын
Thanks Arjan for making this video (and all your videos). You are terrific at teaching. Please make the video on Pendulum if you have an opportunity.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks for the suggestions, Jeffrey, I've put it on the list.
@hdb-1999
@hdb-1999 2 жыл бұрын
Thank you for taking the time to make this video. I have been looking for a video like this for a while.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Henry, glad the content is helpful!
@virtualraider
@virtualraider 2 жыл бұрын
Great video as usual. Small nit, tho: using single quotes within f-strings isn't the only way to access quoted values like dict's. You can also use triple quotes. It's noisier, but you can 😉 `print("""Like so: { dictionary["key"] }""")`
@ArjanCodes
@ArjanCodes Жыл бұрын
Ha, good point!
@stevegrimes5105
@stevegrimes5105 2 жыл бұрын
Thanks for another great video. I've been watching your videos during my lunch break each day and they've really helped me with my "100 days of Python" course.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, Steve the content is helpful!
@jace3789
@jace3789 2 жыл бұрын
Ive followed quite a lot of your content enjoy your enthusiasm and knowledgeable videos.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Jace, glad the content is helpful!
@Skrattoune
@Skrattoune 2 жыл бұрын
That's great! I have been looking for such a complete and clear explanation for quite some time. That makes f strings so much more useful !
@Melindrea
@Melindrea 2 жыл бұрын
ooh, this'll allow me to tweak some of the printing options that I haven't touched from my supervisor's code (apart from moving them). he and I don't have the same programming backgrounds, so while it's a bit too strong to say that we "disagree" ... we often don't do things in the same way.
@kdt85
@kdt85 Жыл бұрын
Love the debugging tip!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad you liked it!
@OMGnotThatGuy
@OMGnotThatGuy 2 жыл бұрын
I LOVE f-strings and I use them constantly, but I still managed to learn a few things from this video! I didn’t know f-strings could do time formatting and I didn’t know that the debugging f-strings would honor spaces. The only thing f-strings is missing is lazily evaluated or deferred f-strings. That’s the only reason I ever use format() or Template. It’d be nice to be able to pass lazy f-strings to functions or load them from configs.
@davidagnew8465
@davidagnew8465 2 жыл бұрын
You can build an f-string using normal string methods, compile it using the compile function, and invoke the compiled version using eval(code, 'generated', 'eval'). It will run surprisingly fast.
@OMGnotThatGuy
@OMGnotThatGuy 2 жыл бұрын
@@davidagnew8465 Yeah, but using eval() seems pretty hackish and problematic, especially when you're dealing with strings that have quotes in them. It could become a nightmare to escape properly and eval has negative security implications. I avoid using it wherever possible, doubly so if any variables contain user input. What would be nice is if we had a way to tell python that an f-string was lazy when we defined it. Then it would evaluate when __str__ dunder is called. Something like putting f! instead of f: >>> template = f!"Number: {i:2}" >>> for i in range(8,11): 2 print(template) Number: 8 Number: 9 Number: 10
@eliavrad2845
@eliavrad2845 2 жыл бұрын
​ @Jonathan Maybe a function is more appropriate for this kind of cases? template = lambda i: f"Number: {i:2}" for i in range(8,11): print(template(i)) def my_big_template(name, amount, currency): return f"{name} has deposited {amount:.2}{currency}" for name, amount in zip(people, deposits): print(template(name, amount, "$"))
@copperfield42
@copperfield42 2 жыл бұрын
cool, I didn't know some of these. And about the others form of string formatting, I use them if it is for templates if I use it multiples times and then just call .format on it, otherwise f-string for the win, and now when I check my old code I always change the old formats to f-string...
@adrianfebre7424
@adrianfebre7424 2 жыл бұрын
My one and only format() use case is dynamically inserting variables into a large SQL query (in my case, large multi-line strings, perhaps 50 lines on average).
@alexanderpoplawski577
@alexanderpoplawski577 2 жыл бұрын
In this case it would be safer to use the cursor execute method with parameters to prevent SQL injection.
@adrianfebre7424
@adrianfebre7424 Жыл бұрын
@@alexanderpoplawski577 Interesting! I hadn't thought to do that, but that's a great idea
@matteolatinov6630
@matteolatinov6630 Жыл бұрын
Great video, as always. One possible drawback of f-strings: can't use the /n character for multiline print if I'm not mistaken.
@bls512
@bls512 2 жыл бұрын
I really enjoy learning from your approaches with python programming.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Bo, glad the content is helpful!
@digiryde
@digiryde 2 жыл бұрын
What I learned today. We can all be 'leet' twice per day. But, seriously, another good instructional video.
@davidmurphy563
@davidmurphy563 2 жыл бұрын
Glad you've covered f-strings. Can't wait until the g-string video comes out. ;)
@ArjanCodes
@ArjanCodes 2 жыл бұрын
That will unfortunately only be available on my OnlyFans.
@davidmurphy563
@davidmurphy563 2 жыл бұрын
@@ArjanCodes Haha. Can't wait! Don't forget the "1337" medallion!
@clasdauskas
@clasdauskas 2 жыл бұрын
I'm sure he can pull it off.
@Tweakimp
@Tweakimp 2 жыл бұрын
How do you like jupyter notebooks? This video could have shown the formatting in a notebook without switching between the tabs :)
@alxcnwy
@alxcnwy 2 жыл бұрын
Very cool and useful tips, thanks Arjan!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Alex, glad the content is helpful!
@juanbetancourt5106
@juanbetancourt5106 2 жыл бұрын
4:10 is it possible to use f strings to change: "." as thousand separator and "," as decimal separator? thank you for sharing your knowledge Arjan!
@xlindvain
@xlindvain 2 жыл бұрын
that's my question as well
@alperengencoglu5367
@alperengencoglu5367 2 жыл бұрын
You can check out the built-in "locale" module for that.
@michalbotor
@michalbotor 2 жыл бұрын
try this: ``` import locale val = 1_000_000 loc = locale.getlocale() print(loc) print(f'{val}') print(f'{val:,}') print(f'{val:,.02f}') print(f'${val:,.02f}') loc = locale.setlocale(locale.LC_ALL, 'de_DE') print(loc) print(f'{val}') print(f'{val:,}') print(f'{val:,.02f}') print(f'${val:,.02f}') ``` i used some online ide and it failed because most of them have only us_US installed. if you are on linux you can check what locale you have installed with the following command: ``` ➜ locale -a C C.UTF-8 en_US.utf8 POSIX ➜ ``` these are the one installed on the online ide that i've used.
@michalbotor
@michalbotor 2 жыл бұрын
there is probably also a way to display with locale the currency without hardcoded currency symbol; euros for germany
@sousaguiar
@sousaguiar 2 жыл бұрын
I use this way: print(f"The number is {8000:_.2f}".replace(".",",").replace("_","."))
@paulwilliamson5985
@paulwilliamson5985 2 жыл бұрын
What are best practices for using f-strings with internationalization?
@CaptainCsaba
@CaptainCsaba 2 жыл бұрын
Would love a pendulum tutorial.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks for the suggestions, I've put it on the list.
@CaptainCsaba
@CaptainCsaba 2 жыл бұрын
@@ArjanCodes Thank you!
@user-cg6tx4pd2e
@user-cg6tx4pd2e 2 жыл бұрын
My favorite Python channel in youtube, thanks Arjan :)
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks Frank, happy you’re enjoying the content!
@FabioKasper
@FabioKasper Жыл бұрын
Great tips, Arjan. Thanks!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Fabio, happy you’re enjoying the content!
@lungenbrötchen
@lungenbrötchen 2 жыл бұрын
I use f-strings for everything except If something has to be translated. Most of the projects I am working on are using pyqt and translation is done via qt linguist.
@Gummibandet1
@Gummibandet1 2 жыл бұрын
Is f-strings faster even if you don't actually print a variable? E.g. print(f"Hello World") vs print ("Hello World")?
@dann1kid
@dann1kid 2 жыл бұрын
Thanks for dataclasses man, very useful and only you spot it for me
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad the content is helpful!
@TheSdfasdfsaf
@TheSdfasdfsaf 2 жыл бұрын
Hi Arjan, been watching (and subbed) since you only had less than 5k subscribers. Congrats on hitting 100k! The little roof is called a caret in English.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks Matthew.
@user-hf5be1zu7s
@user-hf5be1zu7s 2 жыл бұрын
thank you so much, saved me a lot of work!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad the content is helpful!
@ClifBratcher
@ClifBratcher 2 жыл бұрын
I've learned to love f-strings, but the modifiers always trip me up. I blame ages of printf-style syntax stuck in my muscle memory. BTW With benchmarking consistent tests, a *minimum* run is actually best result. Averaging balances those minimum runs with random other things the system is doing. That said, if the tests themselves are random, averaging blurs the perfect outliers and makes total sense.
@michalbotor
@michalbotor 2 жыл бұрын
good for you! it is still useful to know this percentage notation: c uses it, go uses it, python still supports it. the more versatile you are the better imho.
@lucskywalker16
@lucskywalker16 Жыл бұрын
7:36 This is called a carat in English. Pronounced the same as carrot, the vegetable.
@pepecopter
@pepecopter 2 жыл бұрын
Hey Arjan. Thanks for the content. I'd love a Better Time video if this fits in your schedule! Cheers and happy weekend.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad the content is helpful!
@sjmarel
@sjmarel 2 жыл бұрын
Other formatting methods should be used in order for beginners to understand why f-strings are so awesome. Nice one again, Arjan!
@MattRose30000
@MattRose30000 2 жыл бұрын
It's still useful to learn them as long as there is so much legacy code floating around on the web.
@sjmarel
@sjmarel 2 жыл бұрын
@@MattRose30000 you are completely right. As a matter of fact, the percentage style formatting is very much a common feature of many langs. Talking about legacy code, what's up with the new Int to Str conversion in python? It broke lots of libraries!
@tir0__
@tir0__ 2 жыл бұрын
Another gem from a great teacher ! 👌🏻👌🏻👌🏻👌🏻👌🏻
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much, glad the content is helpful!
@engcisco
@engcisco 2 жыл бұрын
great video as usual, anytime frame for the next discount on your course?
@_baco
@_baco 2 жыл бұрын
You had me at "1337", hahahaha!!!
@aldrickdev
@aldrickdev 2 жыл бұрын
Hey Arjan, Great video here, there were actually many things here that I didn't know about f-strings. I would like to ask, do you have any plans of making videos on the mypy package? I am trying to get into the habit of using types in my code and its working great especially when used on my own code. The issue I run into is when interfacing with external packages and sometimes their functions have wacky types on their parameters or failing to narrow the type of a variable so that mypy knows that after a specific check a variable is only of a certain type. I feel that these are things that I don't really see covered in other mypy videos and wanted to see if maybe you would.
@youhan96
@youhan96 2 жыл бұрын
Thanks! Learned a lot.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Alireza, glad the content is helpful!
@dslackw
@dslackw 2 жыл бұрын
Many Thanks, veryyyyyy useful 👍
@gkallcentre4816
@gkallcentre4816 2 жыл бұрын
Project bones and project data is a laborious and montous hassle to establish 'what is what' (especially from ssy and disorganised
@paulrobinshaw3593
@paulrobinshaw3593 11 ай бұрын
Hello. Great video. Big help. ^ in english is a caret 😊
@chriskathumbi2292
@chriskathumbi2292 2 жыл бұрын
Finally, a new class. Mind doing a video on reflection in python and how it works?
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks for the suggestions, Chris, I've put it on the list.
@kenhaley4
@kenhaley4 2 жыл бұрын
Very nice! (and I thought I knew f-strings). By the way I oftern use the debugging feature with embedded calculations like so: f"{quantity * price = }". Very handy at times. There needs to be a "cheat sheet" showing all these options. (Is there?)
@rianderous8761
@rianderous8761 2 жыл бұрын
I discovered this week that you can print on multiple lines as well.... try: text = f""" this is a multiline string """ print(text)
@kevincodes674
@kevincodes674 2 жыл бұрын
Great video, really helpful!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Kevin, glad the content is helpful!
@uniqe6812
@uniqe6812 Жыл бұрын
As always, this video is great
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Unique, happy you’re enjoying the content!
@rogifedi1
@rogifedi1 2 жыл бұрын
Great stuff thank you Arjan
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks so much Ste, glad you liked it!
@kosmonautofficial296
@kosmonautofficial296 2 жыл бұрын
Thanks for the breakdown of performance that is interesting! What did you mean when you said this feature is called debugging? Is that the f string term? I don’t think of printing variables as debugging. I was looking into jinja templates for creating some text config files but not sure how it will go compared to doing it with python loops and f strings. I wonder if f strings could ever get more functionality.
@user-hf5be1zu7s
@user-hf5be1zu7s 2 жыл бұрын
Is there a sum up to all the subjects in the video? plz
@cosmicblack
@cosmicblack Жыл бұрын
damn, your videos are so great. I like them a lot. Thanks for your time
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful!
@planetshootproduction1721
@planetshootproduction1721 Жыл бұрын
Quite informative👌
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks ✌️
@patrickdallaire5972
@patrickdallaire5972 2 жыл бұрын
Arjan, I love f-strings, dataclasses and other things that you show up. Unfortunately, where I work, people are still clinging to older versions of python... all the way back to 2.7... how do you convince people to migrate from 2.7 to 3.8 or later?
@dawidskreczko
@dawidskreczko 2 жыл бұрын
Dziękujemy.
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thank you so much Dawid!
@austinbelknap125
@austinbelknap125 2 жыл бұрын
I keep getting linter warnings about using f strings for logging. I think it has it’s own %-style parsing that is lazily evaluated.
@mehdicherifi6289
@mehdicherifi6289 2 жыл бұрын
Great tutorial
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks Mehdi, happy you’re enjoying the content!
@Rapha5l
@Rapha5l Жыл бұрын
I still use .format() when I need cariage return or tab in my string ("/n","/t"). How do you manage to use that kind of special caracter with f-string? (I use f"{chr(10)}" but I think it is harder to read than "/n")
@michalbotor
@michalbotor 2 жыл бұрын
i really like f-strings, but it doesn't mean that i find them to be always a superior choice. f-strings are great then we directly access a variable, but not so much when we wrap it in a function call, then i prefer formatted strings, like in the example below: ``` def greet(h: int) -> str: if 0
@ramimashalfontenla1312
@ramimashalfontenla1312 2 жыл бұрын
Really useful!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thank you Rami, glad you liked the video!
@mehboobstudiophotography1283
@mehboobstudiophotography1283 2 жыл бұрын
know what they tNice tutorialnk, and hopefully give so pointers. Thank you!
@robertlove2168
@robertlove2168 2 жыл бұрын
At the start you showed how to print 800 as a hex number but it didn't look like 0x320. Is that possible with an f-string option?
@airatvaliullin8420
@airatvaliullin8420 2 жыл бұрын
You can also use string concatenation as another formatting option, but there is no reason to
@ipadista
@ipadista 2 жыл бұрын
Do one about pendulum!
@ArjanCodes
@ArjanCodes 2 жыл бұрын
Thanks for the suggestions, I've put it on the list.
A Deep Dive Into Pathlib And The Magic Behind It
16:56
ArjanCodes
Рет қаралды 47 М.
7 Python Code Smells to AVOID at All Costs
22:10
ArjanCodes
Рет қаралды 371 М.
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 15 МЛН
At the end of the video, deadpool did this #harleyquinn #deadpool3 #wolverin #shorts
00:15
Anastasyia Prichinina. Actress. Cosplayer.
Рет қаралды 16 МЛН
5 More Useful F-String Tricks In Python
9:38
Indently
Рет қаралды 48 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
5 Tips To Achieve Low Coupling In Your Python Code
18:30
ArjanCodes
Рет қаралды 96 М.
A Deep Dive Into Iterators and Itertools in Python
21:01
ArjanCodes
Рет қаралды 61 М.
Python Decorators: The Complete Guide
27:59
ArjanCodes
Рет қаралды 153 М.
8 Python Coding Tips - From The Google Python Style Guide
17:12
ArjanCodes
Рет қаралды 157 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 302 М.
Protocol Or ABC In Python - When to Use Which One?
23:45
ArjanCodes
Рет қаралды 201 М.
How to Document Your Code Like a Pro
19:03
ArjanCodes
Рет қаралды 91 М.