15 Python technical interview questions you should know

Python is the third most in demand programming language. This is why we ask common Python interview questions to help job interviews succeed. Recruiters can also refer to this position to get the correct set of common python coding interview questions to evaluate candidates.

1. Naming some features of Python?

Answer:
Here are some key points:

  1. Python is an interpreted language. This means that unlike languages ​​such as C and its variants, Python does not need to be compiled before running. Other interpreted languages ​​include PHP and Ruby.

  2. Python is dynamically typed, which means you don't need to declare the type of a variable when you declare a variable or something similar. You can do something like x=111, then x="I'm a string" without error

  3. Python is very suitable for object-oriented programming because it allows defining classes as well as composition and inheritance. Python has no access specifiers (such as
    public and private in C ++). The reason for this is "we are all grown up here"

  4. In Python, functions are first-class objects. This means they can be assigned to variables, returned from other functions, and passed to functions. Classes are also first-class objects

  5. Writing Python code is fast, but running it is usually slower than compiled languages. Fortunately, Python allows C-based extensions to be included, so bottlenecks can be eliminated, and often can be resolved. The numpy package is a good example, it is indeed very fast, because many of the numbers it processes are not actually done by Python

2. How to modify the string?

Answer:
No, because strings are immutable. In most cases, you should simply construct a new string from the various parts of the string to be assembled.

3. What are the built-in types available in Python?

Answer:
Python's immutable built-in data types

  1. Numbers
  2. Strings
  3. Tuples

Python's variable built-in data types

  1. List
  2. Dictionaries
  3. Sets

4. List some of the benefits of Python

Reply:

  1. Python is a dynamically typed language. This means that there is no need to mention the data type of the variable when declaring the variable.
  2. Python supports object-oriented programming because you can define classes as well as composition and inheritance.
  3. Functions in Python are like first-class objects. It is recommended that you can assign them to variables, return from other methods and pass them as parameters.
  4. Development in Python is fast, but running it is usually slower than compiled languages.
  5. Python has many uses, such as web-based applications, test automation, data modeling, big data analysis, and so on.

5. Why use the "pass" statement?

Answer:
The syntax requirement of Python is that the code block cannot be empty. However, empty code blocks are useful in many different contexts, for example, if you want to design a new class using some methods you don't want to implement:

class MyClass(object):
    def meth_a(self):
        pass

    def meth_b(self):
        print "I'm meth_b"

If you miss the pass, the code will not work and an error will occur:

IndentationError: expected an indented block

Other example passes we can use:

Ignore (all or) a certain type of Exception
deriving an exception class
that does not add new behavior. Test the code can run correctly for several test values ​​without caring about the results

6. What are local variables and global variables in Python?

Answer:
Global variables: Variables declared outside the function or in the global space are called global variables. Any function in the program can access these variables.

Local variable: Any variable declared inside a function is called a local variable. This variable exists in local space instead of global space.

7. What is a descriptor?

Answer:
Descriptors have been introduced into Python since version 2.2. They enable developers to add managed properties to objects. The methods required to create a descriptor are get, set and delete. If you define any of these methods, then a descriptor has been created.

Descriptors bring a lot of magic inside Python. They are what makes properties, methods and even super functions work. They are also used to implement the new style classes also introduced in Python 2.2.

8. What are the benefits of using Flask?

Answer:
Flask is part of the micro-framework. This means it will hardly rely on external libraries. It makes the framework lightweight, with almost no update dependencies, and reduces security vulnerabilities.

9. Does Python have a switch-case statement?

Answer:
In Python, we don't have a switch-case statement. Here, you can program the switch function you want to use. Otherwise, you can use a set of if-elif-else statements. In order to achieve this function, we can use a dictionary.

def switch_demo(argument):
    switcher = {
    
    
        1: "January",
        2: "February",
        3: "March",
        4: "April",
        5: "May",
        6: "June",
        7: "July",
        8: "August",
        9: "September",
        10: "October",
        11: "November",
        12: "December"
    }
    print switcher.get(argument, "Invalid month")

10. What are pickling and unpickling?

Answer: The
pickle module implements a basic but powerful algorithm for serialization and deserialization of Python object structures.

Pickling-is the process of converting the Python object hierarchy into a byte stream

Unpickling-is the opposite operation, whereby the byte stream is converted back to the object hierarchy.

11. When do you use tuples vs lists vs dictionaries in Python?

Answer:
Use atuple to store a series of items that will not change.
Use alist to store the sequence of items that may change.
When you want to associate two item pairs in dictionary, use a.

12. What is a negative index in Python?

Answer:
Python sequences can be indexed positively or negatively. For positive indexes, 0 is the first index, 1 is the second index, and so on. For negative indexes, (-1) is the last index, (-2) is the penultimate index, and so on.

13. Assuming lst is 2, 33, 222, 14, 25, what is lst-1?

Reply:

It's 25. A negative number means you are counting from the right instead of from the left. Therefore, lst[-1] refers to the last element, lst[-2] is the second to last element, and so on.

14. How to list the functions in the module?

Answer:
Use the dir() method to list the functions in the module:

import some_module
print dir(some_module)

15. What is PEP 8?

Answer:
PEP 8 is the latest Python coding standard and a set of coding recommendations. It guides the delivery of more readable Python code.

I still want to recommend the Python learning group I built myself : 721195303 , all of whom are learning Python. If you want to learn or are learning Python, you are welcome to join. Everyone is a software development party and share dry goods from time to time (only Python software development related), including a copy of the latest Python advanced materials and zero-based teaching compiled by myself in 2021. Welcome friends who are in advanced and interested in Python to join!

**The following content is useless, this blog is used by search engines
(* ̄︶ ̄)(* ̄︶ ̄)(* ̄︶ ̄)(* ̄︶ ̄)(* ̄︶ ̄)(* ̄︶  ̄)(* ̄︶ ̄)(* ̄︶ ̄) What
is python? How long does it take to learn python? Why is it called crawler
python? Crawler rookie tutorial python Crawler universal code python Crawler how to make money
python basic tutorial Web crawler python python Crawler classic examples
python reptiles
(¯)¯ *) (* ¯)¯) (¯)¯ *) (* ¯)¯) (¯)¯ *) (* ¯)¯) ( ¯)¯) ( ¯)¯)
above The content is useless, this blog was crawled and used by search engines

Guess you like

Origin blog.csdn.net/aaahtml/article/details/113030262