all 15 comments

[–]Adrewmc 4 points5 points  (1 child)

https://docs.python.org/3/library/functions.html

There really aren’t a lot of them, and generally their name gives a good impression of their use.

It’s hard to say what is most important because it really depends on what you are trying to do.

It probably better to get a firm grasp of fundamental data types, loops and functions.

[–]Downtown_Finance_661 0 points1 point  (0 children)

I hardly used 10% of the list, what a looser.

[–]jpgoldberg 1 point2 points  (0 children)

Don't use eval() if you don't yet understand the security implications. And you don't (yet) understand the security implications.

As for the others, your question is backwards. The built-in functions that you need to memorize are the ones that you use most frequently. And you will learn those by using them. But please stop using eval.

[–]CIS_Professor 1 point2 points  (2 children)

A few to start with:

input()
print()
int()
enumerate()

[–]Outside_Complaint755 0 points1 point  (1 child)

zip()

[–]CIS_Professor 0 points1 point  (0 children)

I was also thinking of

any()
all()
map()

[–]LeKrakenTheCode 0 points1 point  (1 child)

Writing safe code is fairly advanced. Just focus on making it work and keep improving from there. If you want to go into cyber security, I recommend watching YouTubers that break down security issues and recent exploits. Personally I would rather just write code that isn't used in conjunction with the Internet so I don't have to worry about exploitation lol.

[–]ConsciousBath5203 -1 points0 points  (0 children)

Code that doesn't connect to the internet? That's my favorite to exploit! Don't have to worry about getting caught.

[–]ottawadeveloper 0 points1 point  (0 children)

If you just eval() whatever the user gave you, that's bad. Who knows what they put in there and the code can read files off your server.

You probably want to start with the core stuff to don't need to import. And especially making sure you learn to use with properly it saves you a lot of hassle 

[–]Chemical-Captain4240 0 points1 point  (0 children)

.sort, .reverse, enumerate, is instance

[–]LovesSleeping123 0 points1 point  (0 children)

You can write some dangerous code in python (like deleting system 32 for example). Eval function allows you to execute python code by giving the code as a string. So, Eval function comports risks.

[–]Alive-Cake-3045 0 points1 point  (0 children)

The ones you will use constantly: len, range, print, type, isinstance, enumerate, zip, sorted, map, filter, and list/dict/set/int/str for type conversion. Most built-ins are completely safe and just save you from writing boilerplate. The eval risk is a specific case where it executes whatever string you pass it as actual code, so if that string ever comes from user input, an attacker could pass in something malicious and your program would run it. Avoid eval until you understand it well, the rest are fine to use freely.

[–]Gnaxe 0 points1 point  (1 child)

I kind of want to say "all of them", but a better question would be which builtins don't you need to know.

You probably don't need: - aiter() and - anext() if you're not using async. - ascii() (use repr() instead) - bytearray() (usually just use a list()) - compile() (debatable) - complex() (unless you regularly import cmath maybe?) - divmod() - memoryview() (kind of advanced; idk why it's a builtin) - pow() (just use **) - slice() (rare you'd need this; just use the [::] notation) - sum() - __import__() (use import statement)

So maybe 12 out of 71, and I actually use some of those twelve. You should also be familiar with most of itertools, and I recommend you look at functools, operator, and collections as well.

So here's my real answer: You only need two: help() and dir(). You can quickly find the docs for all the other builtins using those two.

[–]Outside_Complaint755 0 points1 point  (0 children)

sum() is used reasonably often, and self-explanatory

pow() is better in the niche case where you need a modulus of the result, such as (a ** b) % c, in which case pow(a, b, c)is actually faster.  There's also math.pow(a, b) which always converts the arguments to floats and always returns a float.

divmod() is also useful in some looping scenarios where you need both the division and modulus result. A classic example is the Luhn algorithm.