Python Forum
Seniors, please answer this
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seniors, please answer this
#1
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
Reply
#2
Sharing your own answer to these questions would be nice start of the discussion.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
(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.
Reply
#5
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
Reply
#6
(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:
Reply
#7
OK Guess I could see that occurring.
I don't write many games, so it hasn't been an issue for me.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020