четверг, 2 февраля 2023 г.

Python Interview Questions



Most frequently asked questions

Data Types in Python

Text Type:str
Numeric Types:intfloatcomplex
Sequence Types:listtuplerange
Mapping Type:dict
Set Types:setfrozenset
Boolean Type:bool
Binary Types:bytesbytearraymemoryview
None Type:NoneType

Generator

 - generator is a function that returns an iterator that produces a sequence of values when iterated over. Generators are useful when we want to produce a large sequence of values, but we don't want to store all of them in memory at once.

def my_generator(n):
    # initialize counter
    value = 0

    # loop until counter is less than n
    while value < n:
        # produce the current value of the counter
        yield value
        # increment the counter
        value += 1

# iterate over the generator object produced by my_generator
for value in my_generator(3):
    # print each value produced by generator
    print(value)

Immutable / Mutable data types

Mutable: list, sets, and dictionary
Immutable: int, str, bool, float, tuple

Difference list and tuple

Coroutine


Комментариев нет:

Отправить комментарий