It doesn't capture in the sense of assignment to the name, e.g. you can say case x: return f"{x} not found" but if you tried something like case _: return f"{_} not found" you would get a name error
Hey, I'm loving these videos! I consider myself pretty good at python so I started watching to make sure I'm not missing any knowledge. But instead I find myself watching your videos just because I enjoy them!
Thank for the great tips. Being new to python and learning it from books, I noticed that all you variable declaration are followed by colon (Ex: values: list[int] = ...) as well as declaring the return type of functions or methods. Is this a new version of Python? Does Python enforces this like in other languages? Initially, I was confused reading the code such as "state: tuple[str, str, int] = ('Bob', 'Programmer', 27)" as most books I read don't use that format and other languages use the other way (Ex: int score = 75).
it is called "type annotation" or "type hint", it is a feature that is not enforced by python, the python interpreter even ignores it, but it is good practice to use it for several reasons: 1) Dynamic code editors (pycharm, VSCode, etc...) will use them to infer variable types and warn you when type hint and value do not match 2) the same code editors can better help you with apropriate contextual propositions when you call methods on your variables 3) type hinting arguments in functions makes said function more self-explanatory, it is part of a good clear documentation 4) if you install a static python type checker such as mypy, it is useful for it to work as expected
I was surprised that you didn't cover this in the number formatting segment but the underscore can also be used as an f-string formatter to render large numbers: my_big_int: int = 1242998325235625656975629564965932645346536952465 print(f"{my_big_int:_}") #
I like the underscore for tuple unpacking esp. when you only need one value from a whole bunch. As the underscore is a "throw away variable" you can use it more than once. For example you only want the profession from the following, poorly created example, you can unpack it like this: ("Bob", "Smith", "Developer", "Python") = _, _, profession, _
A variable/function you can(/should) only use in its class OR subclass is not (semi)private, that's (semi)protected. When it's (semi)private, it also can't(/shouldn't) be used in a subclass. I really wonder why you don't have any actual private or protected variables/functions you CAN'T even use somewhere else even if you would try. That's pretty standard in other object oriented languages like C++, C#, Java, or PHP and I don't see a reason why Python shouldn't have this.
I'm going to come clean guys... I use snake case for functions eg do_this_thing and camel? For variables eg newVar, constants stay capital, anyone have a better idea to maintain readability of all the different methods/vars?
I generally find it best to adhere to the conventions of whichever language I'm programming in. So in C, snake_case_for_variables_and_functions, camelCaseForTypedefsAndStructs, and, UPPER_SNAKE_CASE_FOR_CONSTANTS_AND_MACROS. In Java, camelCaseForVariablesAndMethods, PascalCaseForClassesAndInterfaces, UPPER_SNAKE_CASE_FOR_CONSTANTS, and, dot.case.for.packages. Other devs expect these conventions to be upheld and many mistakes can be avoided by keeping your code consistent with them.
One project, they set the 'standard' to use camel case for vars and funcs, but for vars the first letter was always lower case. So something like: myAge: int = 42 UpdateAge(currentAge: int) -> int return curretAge+1 But some folks don't care so much, others get quite passionate. Use something but most important, stick with your choice.
@@mikefochtman7164 Agreed. The most important thing is that your code is consistent. FYI, the first letter of the variable being lowercase is camel-case. If the first letter is upper case along with the first letter of all other words in the variable name, it's Pascal-case.
There's no such thing as "private", ever! Even in languages with managed runtimes, if you find an arbitrary code execution bug, you can read any piece of memory or execute any piece of code, including those marked as private. 👀
Hello Bob!
BTW, in the final example with "case _", the underscore also acts like any variable, matching true to any expression and capturing it.
It doesn't capture in the sense of assignment to the name, e.g. you can say
case x: return f"{x} not found"
but if you tried something like
case _: return f"{_} not found"
you would get a name error
Hello
Hey, I'm loving these videos!
I consider myself pretty good at python so I started watching to make sure I'm not missing any knowledge.
But instead I find myself watching your videos just because I enjoy them!
Really appreciate it! Makes me happy to hear this :)
@@Indently Please keep making videos! I'll be eagerly waiting!
Same. I really enjoy these. They are concise, informative, and I find find them quite relaxing. :)
ditto
Hi Bob!
Loved the vid, thanks a lot :)
Thank for the great tips. Being new to python and learning it from books, I noticed that all you variable declaration are followed by colon (Ex: values: list[int] = ...) as well as declaring the return type of functions or methods. Is this a new version of Python? Does Python enforces this like in other languages? Initially, I was confused reading the code such as "state: tuple[str, str, int] = ('Bob', 'Programmer', 27)" as most books I read don't use that format and other languages use the other way (Ex: int score = 75).
it is called "type annotation" or "type hint", it is a feature that is not enforced by python, the python interpreter even ignores it, but it is good practice to use it for several reasons:
1) Dynamic code editors (pycharm, VSCode, etc...) will use them to infer variable types and warn you when type hint and value do not match
2) the same code editors can better help you with apropriate contextual propositions when you call methods on your variables
3) type hinting arguments in functions makes said function more self-explanatory, it is part of a good clear documentation
4) if you install a static python type checker such as mypy, it is useful for it to work as expected
Type annotations were introduced in python 3.5, which was released 10 years ago (in 2014), so no, it's not a new feature.
The Python language has multiple versions. Which version was your book teaching?
hi, I like your videos and so bought all your lessons on udemy. Hope I can grasb python! Thank you for the videos!
Glad to hear you enjoy the videos! Thank you for the support! Happy learning :)
very helpful
Hi Bob. Awesome channel
Thanks you 🎉
Hello, why didn't you use type annotations when declaring self.brand?
Awesome.
I was surprised that you didn't cover this in the number formatting segment but the underscore can also be used as an f-string formatter to render large numbers:
my_big_int: int = 1242998325235625656975629564965932645346536952465
print(f"{my_big_int:_}") #
Wow, this is cool! :)
@@rusektor You can do a comma instead of the underscore for comma separation -- cool stuff!
@@banjohead66 Oh! That works! Is there also something interesting? ))) I know that I can write print(f"{num = }" instead of print(f"num = {num}") 🙂
@@rusektor Yeah! I use that one all the time! It's incredibly useful/convenient!
@@rusektor He made a whole video about cool f-string syntax where he covered this number formatting and other useful tricks
what is the Self type used for and how do you use it?
What's the code edittor and plug in?
Good one!
Olá Bob!!!
By the way in the 2nd example you mixed up camelCase and PascalCase
Hello Bob!
Bob = True
TY
Hello, Bob!
Can you please also make a game in python.??
Hi Bob, when did you learn python?
Use _('string to translate ')
Hi Bob!
Thumbs up for “in modern English known as a comma”. 😂
Name mangling. I never realized how awkward this term is. "namangling".
Almost forgot... Hi Bob!
Cool_cool_cool_😬
Wait, name mangling exists?
Gr8 m8
Yee, i knew it
English American have been bad with Numbers, too. The confusion is perfect after the million
I also am English American and have been very bad with Numbers, too.
Such perfect confusion...
I like the underscore for tuple unpacking esp. when you only need one value from a whole bunch. As the underscore is a "throw away variable" you can use it more than once. For example you only want the profession from the following, poorly created example, you can unpack it like this:
("Bob", "Smith", "Developer", "Python") = _, _, profession, _
🚀💥
Hello Bob
A variable/function you can(/should) only use in its class OR subclass is not (semi)private, that's (semi)protected. When it's (semi)private, it also can't(/shouldn't) be used in a subclass.
I really wonder why you don't have any actual private or protected variables/functions you CAN'T even use somewhere else even if you would try. That's pretty standard in other object oriented languages like C++, C#, Java, or PHP and I don't see a reason why Python shouldn't have this.
Hello bob
I'm going to come clean guys... I use snake case for
functions eg do_this_thing and camel? For variables eg newVar, constants stay capital, anyone have a better idea to maintain readability of all the different methods/vars?
I generally find it best to adhere to the conventions of whichever language I'm programming in.
So in C, snake_case_for_variables_and_functions, camelCaseForTypedefsAndStructs, and, UPPER_SNAKE_CASE_FOR_CONSTANTS_AND_MACROS.
In Java, camelCaseForVariablesAndMethods, PascalCaseForClassesAndInterfaces, UPPER_SNAKE_CASE_FOR_CONSTANTS, and, dot.case.for.packages.
Other devs expect these conventions to be upheld and many mistakes can be avoided by keeping your code consistent with them.
One project, they set the 'standard' to use camel case for vars and funcs, but for vars the first letter was always lower case. So something like:
myAge: int = 42
UpdateAge(currentAge: int) -> int
return curretAge+1
But some folks don't care so much, others get quite passionate. Use something but most important, stick with your choice.
@@mikefochtman7164 Agreed. The most important thing is that your code is consistent. FYI, the first letter of the variable being lowercase is camel-case. If the first letter is upper case along with the first letter of all other words in the variable name, it's Pascal-case.
If your example were in an array you would count from 0, so there would be eleven examples.
I think the only way to make anything "private" is using a decorator/wrapper, right?
There's no such thing as "private", ever! Even in languages with managed runtimes, if you find an arbitrary code execution bug, you can read any piece of memory or execute any piece of code, including those marked as private. 👀
@@vlc-cosplayerIn Java with Security Manager enabled, you‘ll have a hard time as such bugs are considered harmful and chased down quickly.
In 8-th You didn’t mention if hidden id is still accessible via self.__hidden_id inside the class definition.
It is, otherwise what would be the point? store unnecessary data?
i think you already made that video?
Hey bob..
How's it going, Bob?
Hello _!
Who is Bob?
why is bob?
My underscore game is weak.
what Bob did to you?)))
still no comments :( im telling this instead of "im second"
So i guess you dont use your brain to read 1_000_000_000_000
Hi Bob!
Hi Bob!