I know it's a simple question, but I've done a lot of research and I'm not finding a simple solution.
I need to create a function that receives a date in "28122016" format and converts it to "2016-12-28" . How can I do this?
I'm trying to perform an exercise to show the perfect numbers present within a given range, but I can only do this to the perfect fourth number. If I increase the range, it takes a long time and does not respond:
def perfeito(n_max):
lista...
In Python it is possible to declare a function inside another function, as shown in the following code.
def foo(palavra=None):
print(palavra)
def bar(outra_palavra=None):
print(outra_palavra)
if __name__ == '__main__':
fo...
Hello! I recently decided to start studying the Python language, however, when researching the language, I noticed that there are differences between version 2 and 3. Are these differences really significant?
The Shannon entropy is given by the formula:
WhereTiwillbethedataextractedfrommynetworkdump(dump.pcap).TheendofanHTTPheaderonaregularconnectionismarkedby\r\n\r\n: ExampleofanincompleteHTTPheader(couldbeadenialofserviceattack): Mygoalistocalc...
In the following code:
first_part = 46
last_part = 57
guess = f'{first_part}{last_part}'.encode()
print(guess)
print(type(guess))
But I did not understand the code snippet:
guess = f'{first_part}{last_part}'.encode()
I need an explana...
In Python, there are two statements that are used to reference variables external to the local scope: global and nonlocal .
What's the difference between the two statements?
When to use each?
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...
How does it work if there are two (+) return in a Python function? Would you like to return the second value, or just the first one?
Example:
def soma(a, b):
x = a + b
y = 'qualquer coisa'
return x
return y