Questions tagged as 'python'

2
answers

What does "return" do in Python?

What "really" return does in Python, especially in recursive functions. Ex. Factorial: def fatorial(n): if n==1: return n return fatorial(n-1) * n     
asked by 26.02.2016 / 03:32
1
answer

What is the 'reduce' function in Python?

In what cases is it useful and how can I use the reduce function?     
asked by 17.04.2018 / 04:18
2
answers

How do I join a list in Python?

When I want to join a array in PHP, I use the function array_merge So: $a = [1, 2, 3]; $b = [4, 5, 6]; array_merge($a, $b); Result:    [1, 2, 3, 4, 5, 6] And how could I do this in Python on a list (I think...
asked by 13.08.2015 / 14:12
1
answer

Is it good practice to carry out imports within methods?

Is there any advantage when performing import within methods rather than performing the "traditional" import in the program header? If I perform the import into the method, will the module be imported only when the method is called? So...
asked by 29.10.2017 / 17:01
2
answers

How do I know if a value is iterable in Python?

How can I do to check in Python if a particular value is iterate? What determines that a given type can be iterate? For example, how do you figure this out in the case below? a = 1 b = 'Uma string' c = [1, 2, 3] d = xrange(1, 10)...
asked by 11.01.2017 / 13:02
1
answer

When to use lists and when to use tuples? [duplicate]

What is the difference between list and tuple types in Python and when should I use each one?     
asked by 26.03.2017 / 01:27
1
answer

What does this "point" in Python mean?

What does this point mean between the variable var and index ? Example: var = ['João','Pedro','André','Alice'] var.index('André') Is there a name?     
asked by 21.04.2017 / 15:42
2
answers

How to do data mining in a txt file with re.finditer

This code can tell me the location of the words batman and sei in the whole txt file: import re f = open('C:/pah.txt','r+') text = f.read() words = ['batman','sei'] for x in words: for m in re.finditer(x,text): prin...
asked by 28.03.2014 / 21:21
3
answers

How to remove the first element from a list in python?

I have the following code: At the command line > teste.py primeiro segundo In the script teste.py : import sys print(sys.argv) And I have the following return: ['c:\teste.py', 'primeiro', 'segundo'] But I would like t...
asked by 05.02.2015 / 15:21
1
answer

How to declare a password input?

I wonder if there is a way to mask character entry in input() of python. Ex: Senha = 1234 Entrada = int(input("Digite sua senha: ")) In the above entry I wanted to change the letters entered by asterisks. Is there any way to...
asked by 31.12.2016 / 22:19