Most voted "python" questions
Python is a dynamic and heavily typed programming language whose design philosophy emphasizes usability. Two similar but incompatible versions of Python are in use (2 and 3). Please mention the version you are using when asking a question about Python.
Learn more…8,642 questions
Sort by count of
-
5
votes1
answer741
viewsSubtract 2 weeks from a full date in Pyhton
I’m thinking a date in this format: time.strftime("%d/%m/%Y") // 00/00/0000 I want to subtract two weeks from that date, but I don’t know how to do it.
-
5
votes3
answers212
viewsCapture the WHERE clause of an SQL query
I need to capture only the clause where several queries to analyze the filters used. For example: select "DIM_1"."col1", "DIM_2"."col2" , "DIM_3"."col3" , "DIM_4"."col4" , "FAT_1"."col5" from…
-
5
votes1
answer3327
viewsReading accented CSV file in Python?
I am learning python3 and ended up getting stuck in the question of reading a simple csv file that contains the character 'à'. I’ve tried using Code, I find that I found through the internet but…
-
5
votes2
answers6502
viewsExtensions . pyc . pyd . Pyo in Python
Since there are certain extensions .pyc, .pyd, .pyo besides the .py in Python, what are the main differences between them? What each one represents?…
-
5
votes1
answer12643
viewscan’t Multiply Sequence by non-int of type 'float'
Error: can’t Multiply Sequence by non-int of type 'float' I am facing this error, I know it involves variable types, but I do not know how to make the entry receive a float type value…
-
5
votes2
answers262
viewsHow secure is my code, with private variables?
class Conta(object): def __init__(self, numero_conta, nome_titular='anonimo'): self.__nome_titular = nome_titular self.__numero_conta = numero_conta self.__saldo = 0.00 def getNomeTitular(self):…
-
5
votes2
answers137
viewsHow do I compare the keys of a hash to a user input?
Filing cabinet: 101;Johnny 'wave-boy' Jones;USA;8.32;Fish;21 102;Juan Martino;Spain;9.01;Gun;36 103;Joseph 'smitty' Smyth;USA;8.85;Cruizer;18 104;Stacey O'Neill;Ireland;8.91;Malibu;22 105;Aideen…
-
5
votes4
answers4955
viewsQuestions about Python functions
I am a beginner in the area of programming and I have doubts about the questions below. I will post the questions and my attempts (all are showing error in the broker). If anyone can help me already…
pythonasked 7 years, 12 months ago Monica da Silva Vasconcelos 87 -
5
votes5
answers29639
viewsHow to convert an int number to string in python?
I need to do an exercise where I input an integer variable of 3 digits and the python has to show it reversed, but up to where I know an integer variable n can do this, but a string can. What can I…
-
5
votes1
answer901
viewsStore password in database
I have an application that needs to store passwords and get them again, this is not just for login check because the stored passwords will be used to provide access to another system (there is no…
-
5
votes1
answer4065
viewsPython, clone the lists
Be the code below: def modif1(lista): lista = [4,5,6] lista = [1,2,3] modif1(lista) print(lista) #resultado: [1,2,3] def modif2(lista): lista[0] = 4 lista[1] = 5 lista[2] = 6 lista = [1,2,3]…
-
5
votes5
answers13183
viewsPython - NIM game
Enunciation You must write a program in the Python language, version 3, which will allow a "victim" to play the NIM against the computer. The computer, of course, must follow the winning strategy…
pythonasked 7 years, 11 months ago Mário Rodeghiero 389 -
5
votes1
answer3970
viewsWhat are built-in functions? And what is your difference from reserved words?
A little while ago I started to study the Python language and in the middle of studies a question arose. What are functions built-in? And what is your difference of reserved words? I was confused by…
pythonasked 7 years, 9 months ago Cleber Lima 145 -
5
votes1
answer4783
viewsHow do I make an infinite loop without bursting the memory?
I’m trying to make a program that requests on a DDE server, so I need to collect the data every 0.1 sec. But with each iteration of the program the computer memory increases and at the end for the…
-
5
votes2
answers3090
viewsFunction that returns the smallest prime number in Python
I was writing a Python code that received a number and returned the first prime number smaller than or equal to that number. I created a function called maior_primo, which does the following:…
-
5
votes1
answer288
viewsStart and Take down bank in flask test
I’m doing an api test, which I pass a json it validates me if it came back all ok: my base class: # -*- coding: utf-8 -*- # base.py import os import unittest from app import initialize from mock…
-
5
votes1
answer104
viewsoffline maintenance of Python modules
Due to problems with internet where I live, I need to maintain the packages and install new ones without the internet connection, keeping a microservicer mounted on Nanopi so that I get the files…
-
5
votes1
answer132
viewsDifferent types of python dictionaries
Is there any way to convert this dictionary: d = {'Ano; Dia; Mes' : '1995; 2; 5'} for this format: d = {'Ano': '1995'; 'Dia' : '2'; 'Mes': '5'} Thank you…
-
5
votes1
answer581
viewsHow to get the 10 most frequent words from in array?
I need to know how to get the ten most frequent words. This code takes all the words of a text and saves how many times it occurred. if len(palavra) > 0: if palavra in conjunto: qtd =…
pythonasked 7 years, 7 months ago Duvida.net 51 -
5
votes1
answer1269
viewsHow the Python 'in' operator works
Could someone explain me the logic of python’s 'in' operator? I did some tests on Idle and still can’t understand how it works. >>> (2 or 10) in range(1,6) True >>> (10 or 2) in…
pythonasked 7 years, 6 months ago Lean Marqs 51 -
5
votes1
answer4205
viewsConvert PDF to text with Python
Well, I have a PDF file that is on a website, I would like to know how to take the text of this PDF and put it in a variable. Access the site with PDF I know, my difficulty is in converting this PDF…
-
5
votes2
answers1757
viewsHide password on terminal
I am developing a python application that will work by the terminal At a certain point, I need to login: print('É necessário informar suas credenciais para se comunicar com a API') email =…
pythonasked 7 years, 6 months ago José Henrique Luckmann 1,084 -
5
votes3
answers26954
viewsPython maximum and minimum
What is the function I use to find the maximum and minimum values between 2 values in Python? Thank you
-
5
votes1
answer276
viewsHow to convert Python encryption to PHP?
I wonder if it is possible to convert this encryption to the PHP language, I need to convert the passwords that were generated to be accepted in my Login system on the site, but I do not know how to…
-
5
votes2
answers461
viewsDo I need to import a module several times?
I have a class file and a file for the main program, in the two files I need Pygame. I import the classes into the main program this way from classes import *. I need to import Pygame into the…
-
5
votes1
answer114
viewsIs it good practice to perform Imports within methods?
Is there any advantage to doing import within methods instead of performing the "traditional" import in the program header? If I import within the method, will the module only be imported when the…
pythonasked 7 years, 3 months ago Bruno Camargo 519 -
5
votes3
answers1309
viewsI want to change a string in 3 positions
I would like to walk 3 positions with a letter of a string, for example, make the letter A turn D, I tried the second command: texto[c] = texto[c] + 3 But it still doesn’t work, what would be the…
-
5
votes3
answers9397
viewsHow to pass arguments by reference in Python?
When I studied Pascal remember that my teacher explained that to pass an argument by reference it was necessary to put var in front of the variable, in the function/procedure parameters. Example:…
-
5
votes1
answer87
viewsWhy does "int('1111', 2)" return "15" in Python?
Why from this exit? Code: a = int('1111', 2) print(a) Exit: 15
pythonasked 7 years, 2 months ago Lucas Braga 99 -
5
votes5
answers11566
viewsHow to find the type of a variable given by the user?
I would like to ask the user to type something and find out what kind of what he wrote. So far I only know the input(), but the input() only returns the type String. If I put int(input()) or…
-
5
votes2
answers1259
viewsWhat are the function of each string prefix in Python?
In Python, we often see strings with a prefix, such as below, where the prefix is used r: r"""OS routines for NT or Posix depending on what system we're on. This exports: - all functions from posix…
-
5
votes3
answers1627
viewsNested lists in python
I need some help, let’s say I have the following list: lista = [1,2,3,4,5,[6,7,8,9],10,11,12,13,14,15] If I wanted to print each of the items on that list I would make one: for i in lista:…
-
5
votes1
answer6199
viewsHow to use Objects.filter in Django?
Good afternoon, I have a model here in my Django Subject, and I want to list it in html, but every subject has as a foreign key the model id category, how I make a variable to receive Objects.filter…
-
5
votes2
answers2728
viewsHow to separate only the first word of each string from a list?
Given that list : nomes = [ " Paulo Ricardo " , " Fabio Junior " , " Roberto Carlos " ] How do I create a new list, separating the last name from the last name and only adding the last name without…
-
5
votes2
answers367
viewsHow to optimize my access to the Python dictionary?
I have a dictionary of the form sequinte: dicionario = {'1':'Banana','7':'Maçã','3':'Pera','2':'Melancia'} If I check the key '2' in the dictionary: if '2' in dicionario:. My programmer intuition…
-
5
votes2
answers323
viewsPython reserved word Yield
What is the difference between the following codes ? def bottom(): yield 42 def bottom(): return (yield 42)
-
5
votes3
answers482
viewsRescue only 10 first Python object records
I am wrapped in a piece of code that I am doing. I need to rescue only the first 10 records of an object that I call into a for loop: listaTabela = [] for aluno in alunos: listaLinha = "" listaLinha…
-
5
votes1
answer1426
viewsWhat is the . isidentifier() method used in Python?
I came across the method string .isidentifier() and also the .isprintable(). Why use them? On what occasions would I wear this?
-
5
votes1
answer53
viewsHow can I make the word not break in half? And leave at most 40 characters per line?
valor = '''In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over…
-
5
votes2
answers2226
viewsSwitch string to high box and remove blanks
I’m trying to make a program in Python 3 that should turn the typed text into upper box and remove blanks. I would like to know what is wrong with my code since it is not eliminating the whitespace.…
-
5
votes2
answers502
viewsIs it possible to use dictionaries inside lists in Python?
I need to scroll through a list that contains dictionaries and present the information of this one. But testing the attributes here .item() and .value() I couldn’t. Look: #6.8 - Animais de…
pythonasked 6 years, 2 months ago Nameless Man 159 -
5
votes4
answers146
viewsPerforming functions with and without creating local variables
Despite the simplicity of this question, I could not find an answer to it on the Internet. Is there any structural/performance difference between the two functions defined below? def F(x): Output =…
-
5
votes1
answer2777
viewsPython file comparison program
Personal I am with a doubt and a great difficulty to create a program that reads 2 files, example doc1.txt and doc2.txt, within the files has the following data: doc1.txt doc2.txt 1 1 1 2 2 5 3 6 4…
-
5
votes2
answers5035
viewsWhat is the range() function in Python for?
What is the function for range() in Python? What is its real use? It’s just a numerical list?
-
5
votes4
answers5739
viewsHow to separate the letters of a string that are inserted into a list and place them in an array?
I have a list with the word "test", arranged in such a way: ['teste','teste','teste','teste','teste'] I would like to turn this list into a matrix, in which the letters are separated from each…
-
5
votes1
answer137
viewsDoubt about Neural Networks
I had finished the course of Neural Networks with python, and simply after having trained my entire neural network, I had a question about the use of it. For example, after my network goes through…
-
5
votes1
answer280
viewsWhat is the difference between "==" and "is" in Python?
Using the two lists below as an example: x = [1, 2] y = [1, 2] And testing: x == y x is y The first test gives True and the second gives False. Why the result is different in both cases?…
pythonasked 5 years, 10 months ago Thiago Krempser 1,878 -
5
votes1
answer23453
viewsHow to filter, select and count data on a pandas.Dataframe?
How to get quantity of records based on multiple columns of a given name? My dataframe looks something like this: import pandas as pd df = pd.DataFrame([["1111", True, True, False, True, True],…
-
5
votes4
answers317
viewsRegex to identify all occurrences of years
I made this Regex to capture the occurrences of years in a sequence of numbers (between 2010-2029). text = '0412020982012' rg = r'20[1-2][0-9]' years = re.compile("(%s)" % (rg)).findall(text) Works…
-
5
votes1
answer992
viewsImage segmentation with Canny Edge Opencv
I’m trying to target the edge of both the iris and the pupil using Canny Edge from Opencv. However all the parameters I used do not meet the criterion of leaving well delimited the two edges. The…