10 Python Basics You Should Know!
HTML-код
- Опубликовано: 10 июл 2024
- 10 Must Know Python Basics and More Tips And Tricks. How many did you already know?
Get my Free NumPy Handbook:
www.python-engineer.com/numpy...
✅ Write cleaner code with Sourcery, instant refactoring suggestions in VS Code & PyCharm: sourcery.ai/?... *
⭐ Join Our Discord : / discord
📓 ML Notebooks available on Patreon:
/ patrickloeber
If you enjoyed this video, please subscribe to the channel:
▶️ : / @patloeber
~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
🖥️ Website: www.python-engineer.com
🐦 Twitter - / patloeber
✉️ Newsletter - www.python-engineer.com/newsl...
📸 Instagram - / patloeber
🦾 Discord: / discord
▶️ Subscribe: / @patloeber
~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
🅿 Patreon - / patrickloeber
#Python
Timeline:
00:00 - Intro
00:08 - 01 Remove elements in List while looping
01:33 - 02 If _name_ == "__main__" do?
02:56 - 03 Check if a file or directory exists
03:58 - 04 Find the index of an item in a List
04:35 - 05 Execute a Program or System Command
05:13 - 06 Merge two Dictionaries
05:55 - 07 Create a nested directory
06:29 - 08 Difference classmethod and staticmethod
07:54 - 09 Difference _str_ and _repr_
08:55 - 10 Concatenate two Lists
----------------------------------------------------------------------------------------------------------
* This is an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏
After every video I think, "Wish I had watched this when I first started Python. Life would have been much easier."
Glad you like it!
Build a time machine ... in Python!
Another great collection of useful tips. Very pithy, so if you’re not particularly familiar with a concept, you need to examine it more closely. A very effective way of presenting. Thanks!!
Thank you! Just thank you!
the best python video i've seen, thank you man. it could be linked in PEP or something
Great video and congrats on 50k!
🎉
Very informative and well edited!
Glad you liked it!
The last one is truly helpful !
Great video. So clearly explained and concise.
Thank you very much!
Great video and explanations! Looking forward to more videos!
Thanks for watching!
Very great and excellent video! I learned a lot from it.
Lot’s of greetings, Dennis 🇳🇱
simply awesome!
Great video, subscribed.
Awesome, thank you!
Thank you very much!
I just wanted to share a note regarding removing elements from the list:
For the examples you gave on "Removing elements in the list while looping", there is a big deference in:
1. creating a copy of the list with list slicing.
2. using list comprehension and assigning that directly to the list.
which is...
imaging that you have:
a = [1, 2, 2, 3, 4]
and you have another list pointing to the first list reference:
b = a
You have two scenarios:
1. if you assigned a sliced copy of that first list to a list comprehension:
a = [1, 2, 2, 3, 4]
b = a
a[:] = [x for x in a if not even(x)]
you are modifying the list "in-place". Thus, "b" will be equal to the NEW list "a" >> both a and b references are pointing to the new list "a".
2: if you assigned the original list directly to a list comprehension:
1. if you used list slicing:
a = [1, 2, 2, 3, 4]
b = a
a = [x for x in a if not even(x)]
you are modifying the list "out-of-place". Thus, "b" will still point to the OLD "a" >> b is the old a but a is now new a.
This is not recommended since you might forget about b (or any other list which is pointing the original list) unless you are aware of that.
Thank you very much again you!
Yes thank you very much for clarification :) I could not fit all of this into this video, but yeah you are right!
@@patloeber You've covered the gist of it which was perfect. I learn a lot from your videos :)
This is EXACTLY the kind of thing that blows my head apart. I mean, I get it, I have to read it, re-read it, think a bit, then re-read it again... I guess what I'm trying to understand, what is the preferred method IF, you wish the original list to retain it's contents while getting a newlist 0f not evens? I need to read up to comprehend list comprehension. I guess the other thing is create some lists and step through, print results and review the outcomes.
8:38 Nice rule of thumb, with this example of developers and customers, I have cleared my confusion.
Thank you Patrick Sir 😊
Glad it was helpful!
Agreed wholeheartedly. I actually "got" that one, lol.
this is really helpful to me. Thanks!
Glad to hear that!
Thank you for making this It's very useful
Glad it was helpful!
Thank you very much for this phantastic video.
glad you like it!
Thank you :)
You're welcome!
Vielen Dank für die zahlreichen hervorragenden Python Videos, wobei dieses hier keine Ausnahme ist. Vor allem mit deinen Pytorch Videos hast du mir Neuronale Netze deutlich einfacher gemacht. Nochmals vielen Dank Patrick.
Bisher habe ich es aber leider versäumt dir dies zu schreiben.
Danke, das freut mich!
Hello Patrik, thank you very much. I'm glad to find your channel. I am programming and learning Python since 3 Year, and I am wondering why I didn't find your channel till now. Thanks to twitter.
This is great stuff. The ultimate test of my ability will be the ability to "stick with you" without hitting pause and/or rewinding repeatedly. As a newb, I find things can go over my head REAL quick. Especially in references to things like 8 - classmethod vs static method... You are for certain a "no messing around kinda guy" on this stuff. Straight, to the point, and move through the material. If we were in a class, I'd be that guy who always jammed my hand in the air and your response would be "Yes Jack, what is it now". It's amazing how one statement can lead to a MILLION questions. Nevertheless, thank you, this is GOLD. Always worthwhile.
As a noob myself I can assure you that this is not noob material or python basics at all. The title is a little bit misleading.
thanks for such content
Glad you enjoy it!
You are awesome! 👏
Thank you! :)
nice video Patrick, have a great day.
Thanks, same to you!
Your correct versions of number 01 are very good, definitely more pythonic, and probably more efficient than mine.
But there is an old solution that I just tried which also works. I used an exact copy of your original code with one change to the for loop line:
for item in a[::-1]:
This change loops through the reversed version of the list. That way when you remove an even item, the odd items that may exist after that even item in the non-reversed list will end up in their correct places.
Like I said, it's an old "trick" from when I was writing in C (not C++) on MS-DOS.
Thanks! Yes looping in reversed order is also possible :)
I stumbled upon that trick when I was first learning python and running into issues modifying lists while iterating through them. I feel like iterating over a copy is more robust and requires less thought.
@@arkie87 Looping backwards is better practice for code quality. Why allocate a whole array if you don't have to. There is a difference between code and good code and choosing which method to do it makes the whole difference. Although I would suggest using traditional for loop for traversing backwards as reversing a list is also time consuming. These small optimizations come in handy when you are working with limited processing and memory power like embedded systems.
Nice video bro 🔥
Thank you!
The BEST python instructor. Thanks for this.
ps. I like the theme you use on that tutorial. May I know which theme is that? is it available for vscode?
Thank you! It's the Blackboard theme and yes it's available for VS Code
Great list. Just for number 6, wouldn't zip() be the best method?
King, you dropped your crown 👑
i love all your videos and they really have been helpful . Can someone please tell what IDE he uses for python in his advanced python concepts playlist.
VS Code. I have a video about my setup here on this channel
For #1 you could just loop backwards to remove elements. This is simpler and avoids copying the array
I was about to say this. Yes this is much better than creating a copy of a list and is much efficient in memory and performance
How will you loop backwards? Can you please enlighten me?
@@LNTraCricEd index using [::-1]
Thnx
👍
Great video. Try using "with" to open files. Makes life so much easier and you don't have to close it later either because it does it automatically for you.
Hi Gazi, a question with that (coming from a newb). Is that the "pythonic" way? Aka, even though it does it automatically (garbage cleanup?) will many recommend we make explicit calls to close vs assuming cleanup?
@@TheJacklwilliams when you use a with statement, the created object is closed after the with block is exited. This can happen either by continuing on to the code following it, by returning a value from a function, or when an exception is raised. Either way, you're guaranteed that it will close. It's the pythonic and recommended way for all kinds of objects that need closing.
@@teodorlamort3864 Many thanks Teodor and, of course I can see why then this is the “pythonic way”.
Great video. You can also use .extend() method for last one, It accepts any kind of iterable and add it to the list.
I didn't knew how to deal with 2, 5 and 7. Do you know any tutorial for dealing with directories?
Yep nice tip! extend() is an in-place update, though :) ... Hmm no, maybe I should create one :D
@@patloeber Looking forward to it :)
Very nice channel! Your enunciation, and precision with the english language, adds to the clarity. Just a wild guess, you are also a German speaker? Thank you for giving!
Yes I am, can't hide my accent :D Thank you!
@@patloeber My wife's family is German, that accent associated with engineering, is a good thing!
@@7Trident3 haha thank you! :)
How i use a sprite? Where i put the images?
Pls help
with subprocess if you want to see the results you have to write shell=True, after your list of commands.
I think the os library is inherently more vulnerable and poses security issues, this is one of the main reasons why people recommend pathlibs and subprocess
When will a ready-made Python production course be available?
What type of application would you be interested in?
For 1st example, I suggest another case with `a = list(filter( lambda x: x%2!=0, a))`
Oh yes the good old filter method :)
In last example if we have to print 1,3,2,4 then what will be the code ?
Pls somebody help me
Hi! I want to ask a small question about Python, i. e. is it possible to get the name of a variable inside via a function, like, str = name(a), # str = `a`?
Why would you want the name of a variable? Seems a bit like an xy problem, if you're still interested in getting all variables available to you, you can use globals() to get all globally defined classes, functions and variables, or local() to do the same but only limited to the local namespace
Essentially, could you tell us more about why you're trying to find the name of a variable?
For beginners: When he mentions "Dunder" (dee-under) he means double underscore (__)
Which software did you use to write the code and make the presentation in these videos ?
It seems to be some kinda background with nice color for python code, not an actual IDE :)
good observation! These are actually Screenshots made with carbon.now.sh/
@@patloeber Thanks :)
how to find the index(for the particular item) in a set data structure?
A set is an an unordered collection of unique elements, so the items don't have indices. You can convert it to a list and then call .index()
Which editor is it ?
These are actually Screenshots made with carbon.now.sh/
With the right beat, this would be a future rap hit.
that's a new comment for me😂
You rap at 77bpm. I may even upload a video to prove it lmao. Just listen to your video at the same time as this video and you'll see what I mean. It'd kinda cool tbh ruclips.net/video/aehB8f5l_2Y/видео.html
sir i get this error for your ai snake video please help sir 🙏🙏🙏🙏🥺🥺🥺
pygame.error: Application didn't initialize properly, did you include SDL main.h in the file containing your main() F unction?
Quick Python Refactoring Tips (30 Second videos): ruclips.net/video/D4xLPfetZRY/видео.html
Or just loop backwards as you remove.
I have a feeling you did not truly understand the class and static method, I'm confused as to what their actual purpose is
1st view ❤️
Nice!!
it's my birthday today 👦👦
Happy Birthday then!
you make everyone getting lazy in other languages🤣🤣🤣🤣
Why do you say "d-under" instead of "dunder" 😂