Questions tagged as 'python-internals'

1
answer

What is Ellipsis in Python?

In Python's list of native constants , you can find Ellipsis . print(Ellipsis, type(Ellipsis)) #-> (Ellipsis, <type 'ellipsis'>) In Python 3, there is still the syntactic sugar ... representing Ellipsis . pr...
asked by 01.11.2017 / 12:24
1
answer

Why does 2 * i * i tend to be faster than 2 * (i * i) when i is integer?

The two multiplications, 2*i*i and 2*(i*i) , are equal and should generate the same result, which only changes is the order that the multiplications are made, but apparently they are treated differently by the interpreter. > In th...
asked by 03.01.2019 / 12:19
2
answers

How does the function int deal with the character \ n?

I've created a list: usuarios = ['123\n','123\n4'] I tried to convert index 0 to integer using int() int(usuarios[0]) Result: 123 But when I tried to do the same with index 1: int(usuarios[1]) result:    ValueError:...
asked by 02.12.2018 / 20:43
2
answers

Why should descriptor instances in Python be class attributes?

I'm studying descritores in Python and I found that they should be implemented as atributos de classe for example: class Descriptor: def __init__(self, obj): self.obj = obj def __get__(self, instance, owner=None...
asked by 23.10.2018 / 20:48
1
answer

Why do these two ways of initializing the same list in Python generate structures of different sizes?

It is common to need to initialize a list in Python with a defined amount of elements and we can do this in two ways: 1) multiplying the list with one element by the desired quantity; or 2) use the list comprehensions technique.    Note:...
asked by 01.08.2018 / 02:50
2
answers

What's the difference between namedtuple and NamedTuple?

The module documentation typing states that the two code snippets below are equivalent. Using typing.NamedTuple : from typing import NamedTuple class Employee(NamedTuple): name: str id: int Using collections.na...
asked by 08.06.2018 / 20:32