Posts: 2
Threads: 1
Joined: Feb 2019
Hi,
I got the following questions in one of the python interviews, I answered them but they told me that they need experienced developers. I wonder how these questions will be answered by seniors. It will be very helpful if you can answer.
What is the difference between a unit and an integration test?
What would you say are the most common mistakes made using Python?
Do you ever multithread?
What is monkey patching and is it ever a good idea?
What do these mean to you: @classmethod, @staticmethod, @property?
What's your favorite Python 3 feature (that is missing in Python 2)? Why?
Thank you
Nada
Posts: 8,160
Threads: 160
Joined: Sep 2016
Sharing your own answer to these questions would be nice start of the discussion.
Posts: 2,125
Threads: 11
Joined: May 2017
Feb-18-2019, 12:04 PM
(This post was last modified: Feb-18-2019, 12:04 PM by DeaD_EyE.)
Quote:What would you say are the most common mistakes made using Python? - Indentation errors
- mixed white spaces and tabulators in indentation
- saving the source code with the name of an existing module. For example: os.py, socket.py, sys.py
- The misunderstanding between assignment and mutation. Objects are passed by reference.
- from something import *
- Since Python 3:
bytes -> decode() -> str -> encode() -> bytes
Quote:Do you ever multithread?
Yes, but it's not usable for CPU bound tasks, because Python is single threaded, which is an implementation detail of CPython (GIL).
You better use multiprocessing for CPU bound tasks. Multithreading works for IO bound tasks.
If you have many concurrent connections, the asynchronous model is better (asyncio).
Quote:What's your favorite Python 3 feature (that is missing in Python 2)? Why?
I miss many features in Python 2.7. I just don't use it anymore.
To name some of them: - format strings
- good unicode support
- pathlib
- asyncio
- dataclasses
- multiple star assigment:
head, *body, tail = ['Start', 1, 2, 3, 4, 5, 'End']
print('head:', head)
print('body:', body)
print('tail:', tail) Output: head: Start
body: [1, 2, 3, 4, 5]
tail: End
- math.tau, very important to get rid of the factor 2
- much more...
You try to compare two different languages, where the older one was not extended since 10 years.
Posts: 2
Threads: 1
Joined: Feb 2019
(Feb-18-2019, 11:23 AM)buran Wrote: Sharing your own answer to these questions would be nice start of the discussion. These were my answers :
Quote:What is a difference between a unit and an integration test?
Unittest is used to test the small pieces of the code, while the integration test is used to test the functionality of the entire application.
Quote:What would you say are the most common mistakes made using Python?
Circular import which happens when two modules import each other.
Variables scope issue if using a global variable inside a function without using the global keyword.
Indentation, mixing between tab and space indentation cause an error.
Quote:Do you ever multithread?
Yes, but not in python.
Quote:What is monkey patching and is it ever a good idea?
It’s changing the code of a class or module at runtime. It is useful for testing, but it might be dangerous in production.
Quote:What do these mean to you: @classmethod, @staticmethod, @property?
@classmethod : a method that belongs to a class and has a class instance passed to it
@staticmethod : a method that exists inside the class but doesn’t belong to it
@property: is used as a getter method of a class property
Quote:What's your favorite Python 3 feature (that is missing in Python 2)? Why?
Unlike python 2 that uses Asci, Python 3 uses Unicode as a default representation of strings.
Posts: 12,031
Threads: 485
Joined: Sep 2016
Quote:Circular import which happens when two modules import each other.
I don't think this is very common, I've only done it once or twice, and discovered my error almost immediately
Posts: 5,151
Threads: 396
Joined: Sep 2016
(Feb-18-2019, 03:58 PM)Larz60+ Wrote: Quote:Circular import which happens when two modules import each other.
I don't think this is very common, I've only done it once or twice, and discovered my error almost immediately It seems to happen often with people using pygame. They usually get so far into a game before realizing that they have to completely rewrite the structure. Most often if they have circular imports, they have other faults too that need to be rewritten.
Recommended Tutorials:
Posts: 12,031
Threads: 485
Joined: Sep 2016
OK Guess I could see that occurring.
I don't write many games, so it hasn't been an issue for me.
|