Questions tagged as 'python'

1
answer

What is Yield for?

For some time now I have written some basic scripts with Python, in some tutorials sometimes I get the yield , which usually appears in repetition structures commonly while . What is it for? And how to use?     
asked by 17.10.2015 / 01:11
2
answers

What does the "|=" operator in Python mean?

I was analyzing a code and I came across the |= operator, I would like to know what that means, and what is its practical application. Example: x |= y     
asked by 18.09.2017 / 13:48
1
answer

What are Python 3.8 Assignment Expressions?

Assignment expressions are defined in the PEP 572 that was approved to be implemented in version 3.8 of Python. But what are the assignment expressions and when should they be used? What kind of problem does your implementation seek t...
asked by 25.08.2018 / 00:41
3
answers

Using lower () in a list of lists in Python

If I have a list like this: Lista = [['DE','DO','OU'],['AE','YHH','OO'],['OW','LA','FOR']] And I want to leave it like this: Lista = [['de','do','ou'],['ae','yhh','oo'],['ow','la','for']] How do I? I thought if I did it, I would do it:...
asked by 09.10.2017 / 03:56
2
answers

Xpath with Python

I have the following XML (simplified): <produto refid="cat01" idprod="tv01"> <marca>xxx</marca> <modelo>xxxx</modelo> <genero>xxx</genero> </produto> <v:utilizador iduser="U00000"...
asked by 28.02.2015 / 13:00
4
answers

Switch / case very interesting in Swift - What other languages support this?

The Swift language has a very interesting and intuitive way to work with switch-case breaks, with partial-matching, pattern-matching, etc. techniques, see these examples: let age = 33 switch(age){ case let x where x >= 0 && x <=...
asked by 30.06.2016 / 02:44
3
answers

In Python, what are the consequences of using 'is' instead of '=='

The two forms below return True , but what are the consequences of this in a more complex code? >>> a = '2' >>> a is '2' >>> True >>> a == '2' >>> True     
asked by 24.10.2014 / 23:44
4
answers

Is there a ternary operation in Python?

I often see several programming languages where a ternary operation is almost always identical. (x % 2 == 0) ? "par" : "impar" However, when I tried to do this in Python, it gave me an error: (x % 2 == 0) ? "par" : "impar" ^...
asked by 26.10.2016 / 18:35
2
answers

Why in class declarations in Python should we extend object?

No Python , when we declare a class, we extend object . class StackExchange(object): def __init__(self): pass I do not know if I'm wrong, but I had the impression that in some versions this is mandatory; and not in o...
asked by 04.03.2015 / 21:34
1
answer

What is __all__ used for in Python?

I've seen some Python code whose __init__.py file has a __all__ variable with a list assigned. Example: __all__ = ['foo', 'bar'] I've noticed that in Python, when things start with underline , it means that it'...
asked by 10.01.2017 / 19:17