Questions tagged as 'python'

3
answers

What is the difference between the operator IN and ==?

I would like to know the difference between the IN and the == operator in Python?     
asked by 14.04.2018 / 22:45
2
answers

How to limit decimal numbers in Python?

How do I format a decimal number in Python for a given amount? For example, I want to display only two decimal places of the following number: numero_decimal = 3.141592653589793 How could I turn this number to 3.14 ?     
asked by 09.01.2017 / 19:51
4
answers

Problems with conditional structures

I started programming shortly and I'm doing some Python exercises. The problem is that the result variable always returns "Approved" even when the concept is "D" or "E". I have already broken my head and can not see the error.    Make a...
asked by 18.08.2017 / 22:18
3
answers

How to remove accented expressions with regular expressions in Python?

I'm developing a regular expression to try to replace accents and characters with ç by normal characters Example: á = a ç = c é = e But my regex is only eliminating, any tips? import re string_velha = ("Olá você está ???? ") st...
asked by 21.09.2018 / 19:40
2
answers

Change string to uppercase and remove whitespace

I'm trying to make a program in Python 3 that should turn typed text into uppercase and remove white space. I would like to know what is wrong with my code since it is not deleting the blanks. I tested two codes. First code: print ("-"*50...
asked by 31.10.2018 / 12:02
2
answers

How to separate only the first word from each string in a list?

Given this list: nomes = [ " Paulo Ricardo " , " Fabio Junior " , " Roberto Carlos " ] How do I create a new list by separating the first and last name and only adding the first name without the last name in this new list, using list compre...
asked by 17.04.2018 / 22:25
4
answers

Inverting sequence (PYTHON 3)

Good Night, I'm a beginner in IT and I'm doing a basic python course, I have to implement the following: Write a program that receives a sequence of integers ending with 0 and prints all values in reverse order. ** Note that 0 (ZERO) should n...
asked by 23.03.2017 / 22:21
1
answer

How the 'in' operator works in Python

Could someone explain to me the logic of the 'in' operator of python? I've done some testing on idle and I still can not figure out how it works. >>> (2 or 10) in range(1,6) True >>> (10 or 2) in range(1,6) False In the ab...
asked by 20.07.2017 / 03:15
2
answers

How to format all the elements of a list in Python?

In php, when I want to generate a array formatted, I use the array_map function. So: $numeros = range(1, 10); array_map(function ($value) { return sprintf('%04', $value); }, $numeros); Return: array('0001', '0002', '...
asked by 28.10.2015 / 19:43
2
answers

How to get an item from a list randomly?

Suppose I have the following list: frutas = ['abacate', 'mamão', 'laranja', 'uva', 'pêra'] I need to capture one of these elements of list randomly. How would I do this in Python?     
asked by 09.01.2017 / 19:31