Тёмный
No video :(

+10 CRAZY Ways To FORMAT Text In Python with F-Strings 

Indently
Подписаться 202 тыс.
Просмотров 21 тыс.
50% 1

Python's F-Strings are far more powerful than you think! Here are +10 ways that you can format text in Python with F-Strings. Do you know all of them?
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 42   
@Martin-delta
@Martin-delta Год назад
The = Can be uset to print both variable names and their value. print(f"{foo=} {bar=}") - will print “foo= 1 bar= 2”. Useful for quick debugging.
@Indently
@Indently Год назад
I immediately realised after I uploaded the video that I missed that one
@Martin-delta
@Martin-delta Год назад
@@Indently I even think I learned it from one of your previous videos. :)
@schlopping
@schlopping Год назад
Correction: Not variable name, but expressions! e.g. f"{1+1=}" -> "1+1=2"
@FreihEitner
@FreihEitner Год назад
This is VERY cool and handy info. I'm fairly new to coding in Python but I can already see some users for this.
@tuzaguilar4201
@tuzaguilar4201 6 месяцев назад
Thanks! I was looking for something like this just a day ago.
@grzegorzryznar5101
@grzegorzryznar5101 Год назад
1. Reduce amount of decimals is not the best word in that case, cause the number will be just rounded not cut off ;) 2. Recently, I've discovered, that it is possible to add own format to class via __format__ magic method ;) And then it can be used in fstring for example
@cirklare
@cirklare Год назад
That's why you need to read the manual for anything you buy
@Indently
@Indently Год назад
I'm the kind of guy who buys the Lego™ Death Star, throws away the box, and builds something entirely unrelated.
@ChronicoOne
@ChronicoOne Год назад
As someone who's written a function in Python to properly print out a date, I am grateful for your enlightenment. If you want to be enlightened about machine learning, tap my face😅
@532hariharareddyg5
@532hariharareddyg5 Год назад
best explanation
@yaseralhalaby471
@yaseralhalaby471 Год назад
Thank you for this video, it is very helpful
@Chalisque
@Chalisque 4 месяца назад
Something I like, when defining your own classes, is that whatever you write after the : (e.g. the 'turnip' in {a:turnip}) gets send to the object's __format__(self,formatstring) method. So it's very open-ended.
@GamingAbroad90
@GamingAbroad90 Год назад
i saw these a couple weeks ago, but i didn't know about the last one
@EvokerKing
@EvokerKing Год назад
6:55 could you show us in a separate video how you can make the part set up to handle that in a module similar to the way the datetime module handles it? i know it uses some kind of format function, but that is it.
@manarmimi3073
@manarmimi3073 Год назад
Thank you Good job.
@richardboreiko
@richardboreiko Год назад
Can you indicate AM or PM with the time?
@ayushpurohit8266
@ayushpurohit8266 Год назад
Yes
@emadelazhary2373
@emadelazhary2373 Год назад
Thanks.
@Lanxxe
@Lanxxe Год назад
Is it possible to make a space " " the thousand separator with f-strings ?
@Martin-delta
@Martin-delta Год назад
{:,d} is not locale aware. So the simplest way is just .replace(',', ' ') Or you can use the locale lib and override the default separator. import locale locale.resetlocale() # Load default locale locale._override_localeconv = {'thousands_sep': ' '} # Set space as thousand sep locale.format_string('%d', 123456789, grouping=True) => 123 456 789
@bernardcrnkovic3769
@bernardcrnkovic3769 4 месяца назад
i dont know why i laughed so hard at the start..
@benfurstenwerth
@benfurstenwerth Год назад
datetime.datetime.datetime lol made my morning! Thank you for that
@trp
@trp Год назад
This is so cool
@Heavy_Lvy
@Heavy_Lvy Год назад
How did you causally do the start of the video
@-awwolf-
@-awwolf- Год назад
Is there a way to swap points and commas in floats, as it is written in Germany, for example?
@Indently
@Indently Год назад
Unfortunately, I don't know of any way of doing that with the simple {var:,} syntax, which is really annoying.
@ruzibayevich1693
@ruzibayevich1693 Год назад
I didn't feel how I lost my 9 mins , I didn't wanna watch it till the end actually 😂
@zapp7746
@zapp7746 Год назад
F strings are cool but Zapp's comments are cooler
@yibing8112
@yibing8112 Год назад
watch video before: proficientin in python after: heard python
@howl2339
@howl2339 Год назад
Bananas, mhhhhh
@Mulakulu
@Mulakulu Год назад
Im still disappointed that we can't use a variable in place of that 20 for spacing
@Indently
@Indently Год назад
Yes you can, watch the entire video and you'll see how.
@Mulakulu
@Mulakulu Год назад
@@Indently oh shoot. I'm spreading fake news. Thank you 👍
@nugget7236
@nugget7236 Год назад
Today I learned that a scientific notation is not a error
@Indently
@Indently Год назад
😂
@Lahmeinthehouse
@Lahmeinthehouse Год назад
How is this useful?
@Indently
@Indently Год назад
What do you mean?
@Lahmeinthehouse
@Lahmeinthehouse Год назад
@@Indently why would it be interesting to print something with a lot of spaces and characters? I just don’t see the value in it in general
@Indently
@Indently Год назад
Formatting is a preference. You might want to make some logs look nice to make it easier for a user (or even yourself) to understand.
@Lahmeinthehouse
@Lahmeinthehouse Год назад
@@Indently oh, right! Good point, thank you ☺️
@sg8nj
@sg8nj Год назад
print('{:*^10}'.format('Hi')) try this. Output: ****Hi****
Далее
5 Useful Python Decorators (ft. Carberra)
14:34
Просмотров 98 тыс.
New Dyna Skin is OP🥵🔥 | Brawl Stars
00:16
Просмотров 487 тыс.
Кого из блогеров узнали?
00:10
Просмотров 596 тыс.
5 More Useful F-String Tricks In Python
9:38
Просмотров 47 тыс.
10 Important Python Concepts In 20 Minutes
18:49
Просмотров 66 тыс.
Python's 5 Worst Features
19:44
Просмотров 106 тыс.
5 Good Python Habits
17:35
Просмотров 508 тыс.
F-strings In Python: Everything You Need To Know
23:29
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн
ALL 47 STRING METHODS IN PYTHON EXPLAINED
23:34
Просмотров 128 тыс.