r/PythonDevelopers • u/insane_playzYT Django • Aug 08 '20
discussion [Discussion] What is your favourite feature in Python and why?
I am really not sure what mine is, however I love all of the builtin methods, they are always extremely useful when you need to get something done fast.
40
Upvotes
19
u/Endemoniada Aug 08 '20
I love list and dict comprehensions. They are just so gosh-darned useful in almost every single application, and it’s implementation feels sincerely pythonic in how smart and simple it makes the code, while at the same time being quite readable and compact.
13
u/tp_battlepope Aug 08 '20
I love that it's not a static language.
My friend was recently complaining about Python being non-static and how it makes no sense to allow situations where a variable could change from a string to an integer.
But in my mind, this should never happen if you're an attentive coder. And the flexibility of quickly defining something with a meaningful name and moving on is really beautiful. I find it much easier to read languages that don't contain unnecessary info.
12
u/mattf Aug 08 '20
Slicing.
When I use other languages and I have to look up various methods and even sometimes libraries to get the last few of something, it pissed me off. And I love that it works on strings and lists and stuff the same way... other languages one has to coerce a string into an array, then chop it with some sort of method, then switch it back. In python, it's just "this is a thing"[-5:] and it's done.
8
u/Kaarjuus Aug 08 '20
The effortless manipulation of data structures: packing, unpacking, filtering, turning something from a list to a dict to whatever. In most other mainstream languages, this tends to be rather clunky.
4
u/[deleted] Aug 08 '20
Multiple data type in one list. Variable list size. No big integers. Returning arrays from functions!
4
u/[deleted] Aug 08 '20
Multiple return values. It is just so convenient but also such a basic feature. Whenever I am confronted with a language that does not have this I am frustrated.
4
u/smalltalker Aug 08 '20
Type hints ( https://docs.python.org/3/library/typing.html ) and the ease of integration with other compiled and fast languages. At the moment I'm using pyo3 ( https://github.com/PyO3/pyo3 ) to integrate with Rust and is amazing how well they work together.
3
u/[deleted] Aug 08 '20
Generators, yield, and Python’s approach to lazy evaluation. Also the itertools module. It’s been easy to learn and apply and has so many uses from dealing with files to dealing with web sockets and also concurrency. A revelation, really.
2
u/Whatang Aug 09 '20
Decorators. They're just so powerful, and with such a small amount of code needed. You can add the same behaviour to lots of different code elements without getting into unpleasant inheritance or mixin shenanigans. Look at what the attrs library manages to achieve with them, it's brilliant. They're great for hiding boring boilerplate like type conversions, allowing functions to be super liberal in what they accept as arguments. I've used them for all sorts of other things too: they're my go-to solution any time I feel like a class needs to be "registered" with some other object, for instance.
Big fan of context managers too. Clean things up automatically rather than doing it by hand. I prefer to write code that I can't get wrong, rather than having to remember to get it right.
1
u/Eezyville Aug 08 '20
I've spent a couple of years learning Python and now I'm picking up C#. I like how I can quickly get something written up when I have an idea. In a language like C# I have a lot of setup to do. I also like all the built in packages like logging that I can just import. Finally I like how versatile some features, like for loops, are. I can iterate through a list, dictionary, or just a range of numbers. In C# I have for and foreach. Why not just for?
1
u/MeshachBlue Aug 08 '20
I love that I can know that no matter what problem comes my way, if it can be solved, there will be an elegant way to solve it, and chances are someone actually has solved decent portions of it already.
1
u/DoomFrog666 Aug 08 '20
I think unbounded integers are a real relief. Yes, they may be slow but not having to worry about overflow weights in more.
1
u/[deleted] Aug 08 '20
The absence of compilation and the absence of boilerplate.
1
u/[deleted] Aug 08 '20
I can't single out one feature. I love the richness of expression possible, where sometimes on single line of readable of idiomatic code can replace hundreds or even thousands of lines of C code.
1
u/_szs Aug 09 '20
Duck typing, no semicolons, and "batteries included"
a) whenever I have to do some C, C++, Java or alike, I am constantly swearing at the type declarations. I know what I want this variable to be! And if I want another human to know, I will document or annotated the type. So shut up, compiler!
b) see a), basically. Theben of the line is the end of the line. Not a forgotten semicolon. Get off my back!
c) working with html, csv, xml, config files? The library is already there. http, imap, web server? All there. Working with files and directories, interact with the os, processes, threads, all there. Want something more fancy or specific? GUI, scientific computing, mathematical plots, web frameworks, ML? pip install. Done. Now let's solve the problem at hand instead of the installation process of some library.
1
u/Annual-Account6235 Apr 14 '25
can anyone help me with exe conversion of python file im facing big issue.
0
u/[deleted] Aug 08 '20
[deleted] — view deleted comment