@@hunorfekete7413this wasn't a part of the recent f string improvements. F strings have had this ability since they were added in Python 3.6 (which was in 2016).
Then what are use cases for your suggestions that would be better than fstring? I know one pro is the syntax for yours is easier to remember, but I'm wondering efficiencies or other benefits.
I was making a web scraper just yesterday and wanted to represent the page via a tree diagram. now I know how I can print that tree in a reasonable way!!
The fastest way to learn a different approach to code syntax is to state your intention, and your current iteration. Inevitably people will contribute their own approaches.. and one day on the future, someone desperate will come across your hidden treasure of collected approaches and thank their lucky stars because you will have saved their entire project. 😂🫶
a variable declaration for a variable called `var` with a "type hint" denoting its type as string. Python doesn't by default actually do anything with these but there's type checkers like mypy who can statically typecheck your code.
they are just type hints, don't affect the code in any way or provide performance benefits however it's really useful if you're coding in an editor cause you get type checking and autocomplete
@@fusionsid270how does this work? Is it like typescript checking the type at compile time? I’m assuming at runtime python doesn’t care? I’m not familiar with python at all I’m more of a C# & go guy
@@noahdwhitney yep python doesn't care at runtime, think of them as just comments. They are used to annotate your code and make it easier to read. Also some editors have support for checking the types so if you typed a variable as int but later assign it to a string, The editor will shout at you. However as the python interpreter completely ignores these, even if your ide is shouting at you, the code will still run. You can also get linters such as flake8 to check your code and if you want something closer to a typed language, you can use mypy. It's somewhat similar to typescript's compiler so it'll check your code first then run it
I used it to line up rows in a CLI I was asked to build a while ago. basically lines up individual columns in a table and makes them a lot nicer to look at.
it's a variable declaration for a variable called `var` with a "type hint" denoting its type as string. Python doesn't by default actually do anything with these but there's type checkers like mypy who can statically typecheck your code.
You can add a type to a variable in python but it's only for information. It has no impact on execution. Exemple : myVar : str = "test" myVar = 8 print(myVar) >>>8 Without exception
It’s only a ‘reminder’ of what the coder wanted to use that variable for, so I think you should use it always if you want to remember what were you doing
@@earthbender731it's not entirely necessary in this case since the IDE will recognize it anyway, type hints are much more useful for method parameters over anything else, or for more complex types.
Today you should also learn that there is no “up arrow”. It’s called a “carat”. If you’re going to call it an “up arrow” in a video meant to educate others, you may as well also call the “tilde” a “squiggly line” 🤦🏻♂️ 😒
I don’t regret what I said, nor have any intention of changing it. Over 95% of my followers are non-native English speakers. I’m not an English teacher, I want everyone around the world to understand as much as possible for that is the best thing in terms of communication. I would love to use the correct terms for everything, but it doesn’t matter in this context, go to university 🤣
@@IndentlyOf course you don’t think you did anything wrong. Arrogant narcissist’s never accept constructive criticism or corrections as they already think they are perfect. 🙄 I misspoke in my original reply because some keyboards do in fact contain an “up arrow” key - which makes your statement in this video even more incorrect and more inaccurate. And you really think that an ESL viewer has more chance of knowing “tilde” than “carat”? 🤦🏻♂️ I’ll bet that 80% or more of your ESL viewers know English better than you do - but keep talking down to them and assuming they’re dumb and see how they like it. 😆
@@Indently Well, I started with constructive criticism - but you wouldn’t take it and instead pretended your mistake was intentional and the right thing to do (when it clearly wasn’t). So then, instead of the insults, what would you suggest I say to the next arrogant narcissist I come across that pretends a mistake they made was an intentional choice? 🤔
New python dlc looks crazy ngl
😂😂😂
Python: C edition
I learned this from the replit 100 days of code. You can do it without the character as well. You have left: < right> and center^.
omg this is amazing fr
if you could it would be cool if you include the python version from now on in your description
Python 3 😂
@@irishRocker1but it may be 3.12 cus they buffed f strings there
@@hunorfekete7413this wasn't a part of the recent f string improvements. F strings have had this ability since they were added in Python 3.6 (which was in 2016).
@@hunorfekete7413it works on 3.11.6 at least
Just assume he is using the latest version
If you don't type a symbol after the colon it just uses blank space
Thank you! That's the one question I had from this great Short
Can also use center(), ljust(), rjust()
Yea, but using f-string formatting is faster and feels cooler 😁
Then what are use cases for your suggestions that would be better than fstring? I know one pro is the syntax for yours is easier to remember, but I'm wondering efficiencies or other benefits.
@@Loki- Don't know about efficiency, it's just straightforward.
Incredible!
I learnt that from Rust and I was surprised months ago when I realized it was also in Python 😂🎉
Nice for menus
Good information
Wow, this looks super useful!
Love all your tips.
I was making a web scraper just yesterday and wanted to represent the page via a tree diagram.
now I know how I can print that tree in a reasonable way!!
Nice way of making loading bars
var: str ................... lol
So my assessment code could have been 10x cleaner
Would help in logging, wondering if we could have it js
Before you know it, they'll be adding a graphic representation of your screen and you will use your mouse and a couple of number fields to format.
You making that damn asterisk pyramid would be more better If used that when I was in highschool.
impeccable
I actually use it to display prints in table
This is cool.
Awesome! Python continues to amaze me!!
If you were surprised by that, I wonder what you thought at the f stands for. 😊
Sweet!
YEAH
leftpad has left the chat
What editor kicked leafpad out? I've been learning and using leafpad but just installed PyCharm
Up arrow aka carat
use cases should be describe as well.
Felt nice to see features no one cares about 😅
Wait, is that a python with types? Nice
This ultra rare requirement gets it own syntax in the language. Use a method with a descriptive name.
The ^ seems pretty useful
You've already told these in another video entitled as "+10 Crazy Ways to...." 😅
Why tf does python have a built in left pad too
Is this a new feature?
can you use space as the symbol?
Yes! If you don’t include a symbol to print, it will use a space by default
so zfill but for strings
You forgot about date
Irs a varlous operstor
This might be incredible useful for date formating e.g. 1->01
The datetime module has better formatting options with the strftime() function
@@funkdefied1 ahh good to know, thanks!
The fastest way to learn a different approach to code syntax is to state your intention, and your current iteration. Inevitably people will contribute their own approaches.. and one day on the future, someone desperate will come across your hidden treasure of collected approaches and thank their lucky stars because you will have saved their entire project. 😂🫶
What is( var: str = 'Python')
What is this called i didn't find it on google.
a variable declaration for a variable called `var` with a "type hint" denoting its type as string.
Python doesn't by default actually do anything with these but there's type checkers like mypy who can statically typecheck your code.
That's sick! 0 padding numbers is going to be so much easier
:02d zero pads a digit. 01,02, etc. Change the 2 as required for pad length.
I know what you can't do with fstrings: you can't use them in python 3.5
Didn't know there is static typing in python 😮
they are just type hints, don't affect the code in any way or provide performance benefits however it's really useful if you're coding in an editor cause you get type checking and autocomplete
There isn't, type annotations are just hints for programmers and editors
@@fusionsid270 oh ok
@@fusionsid270how does this work? Is it like typescript checking the type at compile time? I’m assuming at runtime python doesn’t care? I’m not familiar with python at all I’m more of a C# & go guy
@@noahdwhitney yep python doesn't care at runtime, think of them as just comments. They are used to annotate your code and make it easier to read. Also some editors have support for checking the types so if you typed a variable as int but later assign it to a string, The editor will shout at you. However as the python interpreter completely ignores these, even if your ide is shouting at you, the code will still run. You can also get linters such as flake8 to check your code and if you want something closer to a typed language, you can use mypy. It's somewhat similar to typescript's compiler so it'll check your code first then run it
damn kids readin the docs now thats a breakthrough
fstring soup is already an issue as it is, let's make it worse with embedded fstring evaluation!
Im not going to remember this but it looks cool 😂
You might now I've replied to you and you can come back to the post.
@@Wardyworldsthank you
What’s the use case ?
I used it to line up rows in a CLI I was asked to build a while ago. basically lines up individual columns in a table and makes them a lot nicer to look at.
ai showed it yo me yesterday
What could you ever need to do this for
Why is it ‘var: str = ‘ instead of just ‘var = ‘?
it's a variable declaration for a variable called `var` with a "type hint" denoting its type as string.
Python doesn't by default actually do anything with these but there's type checkers like mypy who can statically typecheck your code.
This isn't f string specific
What is this =>
var: str = "Python"
is python become statically typed?
You can add a type to a variable in python but it's only for information. It has no impact on execution.
Exemple :
myVar : str = "test"
myVar = 8
print(myVar)
>>>8
Without exception
It's only a type hint and this feature came with Python 3.5 and therefore has been there for ages
It’s only a ‘reminder’ of what the coder wanted to use that variable for, so I think you should use it always if you want to remember what were you doing
this does nothing to the python compiler/interpreter, it's just for helping remember types mainly for methods
it's the same as a comment # str, to say it should be a string, but if you change it later to an int for example no error will be raised
What would this be used for practically 😂
Exactly my thought.
One thought would be leading zeroes on an ID
Formatting stdout data like logs
Pretty CLIs
Another tool in the toolbox. Which is all of learning programming.
why do you do var: str = "var1" instead of var = "var1"
that's a type annotation, he's stating the data type at declaration
it helps his text editor check for errors and provide suggestions
@@phatboislym does it work in vscode?looks like good practice,im gonna start using that
@@earthbender731yes, it does
@@earthbender731it's not entirely necessary in this case since the IDE will recognize it anyway, type hints are much more useful for method parameters over anything else, or for more complex types.
I have been learning and practicing Python for 1 month and i cant even understand a single line this guy types 😢
Congratulations Python had devised a String butchering syntax even more unreadable than Regex.
great, will never use it anyways :D
Is this for 3.12?
3.6, with the introduction of fstrings
This is incredible!
If you have a favorite string you need to have a life outside of your job.
May I ask, what is the use of this?
Aligning fixed width columns over multiple lines, typically
Child's programming language 😂.
I'm sorry you see it that way :)
And once again, the Python community find something Perl-ish "cool".
Interesting...
It’s cool but is it Pythonic? 🤨
Yea
Copied from rust
Very cool and very useless
Today you should also learn that there is no “up arrow”. It’s called a “carat”.
If you’re going to call it an “up arrow” in a video meant to educate others, you may as well also call the “tilde” a “squiggly line” 🤦🏻♂️ 😒
I don’t regret what I said, nor have any intention of changing it. Over 95% of my followers are non-native English speakers. I’m not an English teacher, I want everyone around the world to understand as much as possible for that is the best thing in terms of communication. I would love to use the correct terms for everything, but it doesn’t matter in this context, go to university 🤣
@@IndentlyOf course you don’t think you did anything wrong. Arrogant narcissist’s never accept constructive criticism or corrections as they already think they are perfect. 🙄
I misspoke in my original reply because some keyboards do in fact contain an “up arrow” key - which makes your statement in this video even more incorrect and more inaccurate.
And you really think that an ESL viewer has more chance of knowing “tilde” than “carat”? 🤦🏻♂️ I’ll bet that 80% or more of your ESL viewers know English better than you do - but keep talking down to them and assuming they’re dumb and see how they like it. 😆
I see you have a particular talent in insulting people on the internet.
@@Indently Well, I started with constructive criticism - but you wouldn’t take it and instead pretended your mistake was intentional and the right thing to do (when it clearly wasn’t).
So then, instead of the insults, what would you suggest I say to the next arrogant narcissist I come across that pretends a mistake they made was an intentional choice? 🤔
Python devs are so cute. Learning that f strings are just *printf* strings in Python flavor.
Flexing in the shorts section on social media is also pretty cute
@@Indently I know 🥰🥰
kkkkk