SoFunction
Updated on 2024-11-19

What's the Difference Between and Methods in Python Explained

1. On a code level, why does the program crash?

1) Reading unassigned variables

Failure to initialize and assign a value to a variable results in a dirty value for that variable.

2) Function stack overflow

Function stack overflows are generally caused by two things:

1. Define a local variable or parameter that is too large. Parameters and local variables are usually stored on the stack, but the stack occupies a very small amount of memory space, only 8M under 32-bit, so if you don't use malloc and new to create memory space on the heap, a stack overflow can easily occur.

2. The level of nested calls to functions is too deep, just like infinite recursion and infinite loop calls.

3) Array access out of bounds

4) The target object of the pointer is not available

For the object pointed to by the pointer to work properly, it has to be a legal, valid, accessible object, like when the pointer isNull or wild pointerWhen you use it again, the program crashes immediately.

And the presence of a null or wild pointer is usually the result of the following operations:

1. Pointer not assigned

/delete frees the object

3. Inappropriate forced type conversion of pointers

5) Parameter errors

Generally, in order to ensure that the parameters are legal, assertions are set to ensure that the program can only run normally if the parameters are legal. Therefore, this kind of error is usually caused by triggering the assertion.

6) ClassNotFoundException exception

This is because the relevant class file is not found in the specified folder where the class is stored.

1. It could be a compilation problem, or it could be caused by the hardware environment at runtime. The same code, run locally no problem, on the server can not find the class. Then I changed the path to scan and it worked.

2. The full class name is not written correctly, or the class is not imported.

3. Pure code or dependency management issues.

Supplement:

First of all, Java's errors are divided into EXCEPTION and ERROR from a programmatic point of view.

error: is a code error, compilation does not pass, run does not work. For example, variable naming is not standardized, public class name and file name is not consistent.

exception: divided into runtime exception and non-runtime exception.

runtime exception: runtime exception, is the program internal exceptions, such as array subscript out of bounds, null pointer, class conversion exceptions.

Non-runtime exception: non-runtime exception, usually caused by the outside world, such as IO e, class not found e, etc.

7) Uncaught exceptions

8) Memory leaks

9) The server is down

One can Versailles a bit of an answer, it must be that the code is written out of specification or the machine can't hold up.

Machines rarely have hardware failures. And the system is the program, so the odds are that if the machine has a problem, it's a program problem that causes all sorts of anomalies.

The above is just to cope with the interview, the right thing to do when encountering a real situation is:

You should take a screenshot of the specific tip of the error and solve the specific problem. Because the problem may be strange, know what the bug is, what causes it, and ultimately to return to solve the problem.

Difference between dead loop and for dead loop?

while dead loop:

while+condition. It is a dead loop when the condition does not change and the condition is always true.

num=1
sum=0
while num<=100:
    if num%2!=0:
        sum=sum+num
print(sum)

for dead loop:

The for loop is mainly used to do iterative operations on iterable data, and can be implemented directly as a dead loop by means of a generator.

def generator():
    index=0
    while True:
        yield index
        index +=1
for x in generator():
    print("It's a dead end:",x)

3. What are the characteristics of a set?

All the elements in a set are unique and it has uniqueness. Collections directly help us to clean up the duplicate data. It is unorganized and fast.

Reference Article:set (mathematics)

What is the difference between the () and () methods in the

()method reads json from a json file, while the()method is to read the json directly, both are converting the string json to a dictionary.

()cap (a poem)()is a json format processing function (it can be understood as such, json is a string).

()function is to encode a list of Python datatypes in json format (think of it this way, the()function is to convert a dictionary into a string).

():

import  json
a={'value':'000','type':'rgb'}
b=((a))
print(a)

():

import  json
c=(open('/Users/llq/PycharmProjects/pythonProject/study/lili/'))
print(c)

5. find out the most occurrences of data in a list using Python?

a=[1,2,33,4,4,4,'a','a','a','a']
print(max(set(a),key=))

summarize

to this article on Python () and () method what is the difference between the article is introduced to this, more related Python () and () method difference content, please search my previous posts or continue to browse the following related articles I hope you will support me more in the future!