Questions tagged as 'python'

2
answers

Python reserved word yield

What's the difference between the following codes? def bottom(): yield 42 def bottom(): return (yield 42)     
asked by 24.06.2018 / 06:14
1
answer

Always prefer xrange above range?

range creates a list in memory with the number of elements defined by the programmer. Since xrange has more performance, I do not know if in all cases, since it does not end up generating a list. Should I always use xrange...
asked by 17.03.2017 / 03:42
2
answers

How to catch all exceptions in Python?

How to catch any exception in Python? Is there a keyword for this? As in Java, just do one try { } catch(Exception ex) { }     
asked by 07.04.2017 / 21:25
2
answers

How to do rounding up with Python?

Is there any native Python way to round up? Example: 10/3 resulting in 4 . What I'm using now is a conditional: x=10 if x % 3 != 0: x += 1 But that's not very practical.     
asked by 24.07.2018 / 18:09
1
answer

String search with "|" character

I need to perform a query in a txt file in Python, however I have 2 problems due to the interpretation of special characters. When I enter | or \ the result ends up being replaced: | is interrupted as white space and \...
asked by 04.09.2018 / 15:45
2
answers

What is the equivalent of 'isset' of PHP in Python [duplicate]

In PHP, if I want to know if a variable was started, I use isset . How can I do the same in Python?     
asked by 18.06.2018 / 08:41
2
answers

Result of multiplication and division with two houses after the comma

Hello everyone, how are you? I'm doing an activity for my python course, it's a script that basically calculates the area of a wall in meters and tells how many gallons will be used for paint. The problem is that when I type a very high value...
asked by 19.06.2018 / 01:06
2
answers

How to stop a loop at a certain time?

I'm a beginner in Python and I'm trying to create an alarm clock ... But it does not "Wake up" on time, can anyone help me? import datetime import time print("Digite a hora para ligar (HH:MM)") t_desp = str(input("")) t_desp += ":00" print("D...
asked by 15.06.2018 / 05:56
2
answers

How to print the percentage sign in Python 2/3?

How do I use% after dialing? Ex: print("%d texto texto 10% texto"%var_a)     
asked by 19.01.2018 / 04:20
1
answer

Optional function parameter

I tried to create a square root function: def root(n, ind): if ind == None: ind = 2 ind2 = 1 / ind print(n ** ind2) I want ind not to be mandatory. I thought that if I did not put it, the value would become...
asked by 13.03.2018 / 21:52