📜 ⬆️ ⬇️

Python. 10 language questions

Several questions that will help to create a general impression of language skills, for example, during an interview

What is the difference between import feathers and import ostrich?

import loads the module into its own namespace:

import feathers
duster = feathers.ostrich("South Africa")

from loads the imported item into the current namespace.
')
from feathers import ostrich
duster = ostrich("South Africa")

The difference between a = [1, 2] and b = (1, 2)

b - unmodifiable tuple

Get the last element of an array

b [-1] if b else None

Get part of the string

"I am string" [0:10]
"File.ext" [- 3:]

What is different record

def a(*args)
print args

from

def a(**args)
print args

The second function accepts named arguments as input:

def a (* args)
print args
>> a (1,2)
(12)
def a (** args)
print args
>> a (one = 1, two = 2)
{'one': 1, 'two': 2}

Difference between __new__ and __init__

In __init__, the object has already been created, __new__ creates it itself, using the parent constructor

Change the values ​​of two variables

a, b = b, a

What is “Rhombic inheritance” and how is it solved in python?

“Rhombic inheritance” is when a class is inherited from several mediation classes, which in turn are inherited from one class. If the common ancestor method was redefined in intermediaries, it is not known which implementation of the method the common descendant should inherit. Python uses the C3 linearization algorithm to solve this problem.

What is a metaclass?

A metaclass is a class whose instances are classes.

How to declare a static method?

@staticmethod
def a ():
pass

Source: https://habr.com/ru/post/68466/


All Articles