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
-
3
votes1
answer1815
viewsDifferences between list, tuple and set
I know that in Python there are three structures that apparently resemble each other, but that in the background there are differences. They are: list, tuple and set. List a = [1, 2, 3, 4] Tuple a =…
-
3
votes2
answers440
viewsHow to do a subtraction operation between two columns of a dataframe and then add the result with another column?
I have this code: dados_train = pd.read_csv('arquivo.csv', delimiter=",") y = ((dados_train.pop('col_name1') - dados_train.pop('col_name2')) + (dados_train.pop('col_name2') When I try to run just…
pythonasked 4 years, 11 months ago Patricia Padula Lopes 183 -
3
votes1
answer1193
viewsWeb scraping with Python (Selenium and Request)
Hello, I am trying to perform a web scraping on a page protected by login, I have already managed to access both via Request, and via Selenium, the problem is after login. The page is as follows:…
-
3
votes1
answer2536
viewsHow to increment a variable in Python?
I’m trying to make a show where he throws a letter on the screen you press it and supposedly you should get a point so I know this is probably a really stupid question, but I tried it in a lot of…
-
3
votes1
answer66
viewsDoubt in the functioning of a Python code (Classes and objects)
Guys, I don’t understand something in this code. I’m importing the Client and Account classes into another program to use them. But I could not understand why it is working, and the deposit method…
-
3
votes1
answer511
viewshow to import classes referencing each other in python?
I have a problem when it comes to importing classes into Python. See, there are 4 files: main: from classeB import ClasseB ClasseB() class A: from classeModelo import ClasseModelo class ClasseA():…
-
3
votes1
answer141
viewsWhat gains do I get in specifying the type of a function’s argument?
It is now possible to define the type of argument that a function will receive. See this small illustration example: def soma1(v1: int, v2: int): return v1 + v2 def soma2(v1, v2): return v1 + v2…
-
3
votes2
answers1851
viewsHow to assign a function to a button in Django Python
I am doing a Jango course and I would like to know if it is possible to assign a function to a button. For example: <form> <label for="word">Digite uma palavra:</label> <input…
-
3
votes3
answers243
viewsUse of functions in Python
I know that it is possible to create functions in the Python to perform certain tasks that normally need to be performed several times within an application. Ex: Paint shop program that calculates…
-
3
votes1
answer112
viewsHow does Python identify which commands are inside if?
In C we have how to inform the size, or how far the function is present as for example: if (n > 2){ ... } but in Python is if n > 2: ... I would like to understand how far these functions end…
-
3
votes1
answer93
viewsA variable in my while is not adding up
I’m new to Python and I’m trying to make an old game I’ve tried in every way to fix this mistake and I can’t, so I ask for help from my consecrated people! My play function has a while that has to…
-
3
votes1
answer162
viewsDoubts Python Matrices
I am trying to create a function that returns the "minor complementary" matrix of any matrix. That is, given an array for example: mat=[[1,2,3],[4,5,6],[7,8,9]] The minor complement associated with…
-
3
votes2
answers4333
viewslist, max/min in python
Hello, I need to make a python algorithm that reads a text file .csv which contains literally 5 million numbers and I need this algorithm to tell me which is the smallest and which is the largest…
-
3
votes2
answers196
viewsPython 3 - Unexpected Flow Control when running IF/IF NOT or IF/ELSE
I’m new to Python, but I already have custom Java software. I would like to better understand why when trying to program a flow control using IF/ELSE or IF/IF NOT the whole block runs. Python code…
-
3
votes3
answers5171
viewsRemove string quotes in array
How can I remove single quotes from the result? Typed user teste and key Esc to get out. The program captures keystrokes and saves digit per digit in a list. The list is hereby filled in: lista…
-
3
votes1
answer71
viewsIs there a better way to group "Ors" in Python without having to type the variable all the time?
Example: letra = input('Digite uma letra: ') if(letra == 'a' or letra == 'e' or letra == 'i' or letra == 'o' or letra == 'u'): print('Vogal')…
-
3
votes2
answers332
viewsTreatment of Python Images
I have a question here of architecture: The application we are building has a load of images pro system. They are photos of ads, and each one can upload 12 photos. These ads are dynamic, meaning…
-
3
votes1
answer42
viewsHow to handle an error within any Python class?
If I do something like: class Foo(object): pass print(Foo().python) **OUTPUT:** AttributeError: 'Foo' object has no attribute 'python' How can I treat this exception within my class, rather than…
-
3
votes2
answers1231
viewsHow to add text to a specific line in Python txt file?
I am trying to store data in a txt file, but I need to save it in specific lines. How to proceed? I’d like to do something like: data = open('arquivo.txt', 'a') data[linha específica].write('Texto…
-
3
votes2
answers187
viewsDoubt about Python’s rstrip function
Any idea why the Python command 'i3-7023'. rstrip('-7023') result only in 'i', while the command 'i3-8819'. rstrip('-8819') result in 'i3'? One would not expect the first command to also result in…
pythonasked 4 years, 8 months ago Mairan Thales Macedo 53 -
3
votes4
answers1030
viewsSum the n odd terms ,using Loop for ,without using list, allowed functions:input,int,print and range
n =(int(input("Digite o número de termos:"))) for i in range(n+n): if i%2>0: print(i) #Não sei como prosseguir depois,como pego esses valores e somo eles…
-
3
votes2
answers256
viewsConvert string to date
I have a date frame whose column that shows me the date has the format 'nov/19' and it’s an Object, I need to convert it to the date format. I know that in the documentation of datetime it is said…
-
3
votes2
answers679
viewsRegular expression to validate a password with Python
Passwords must contain at least 5 words (word = 1 or more letters), each separated by a hyphen, a space, a dot, a comma or an underscore. Example: a-b-b-c-d-d OR Passwords must be at least 8…
-
3
votes1
answer302
viewsImport chatterbot bot to Telegram
I don’t know if that kind of question is welcome here, but come on: I’m developing a chatbot on python and chose the library chatterbot because of the processamento de linguagem natural, by the…
-
3
votes1
answer79
viewsIs it correct to make a user authentication by the backend return message?
Good afternoon, you guys! Earlier I took a question regarding user authentication in my application and after some good tips I was able to authenticate my user, the doubt now is whether the method…
-
3
votes1
answer231
viewsDoesn’t Python3 recognize 0 as int?
The question says I need to receive user entries until a blank line is typed. After the user finishes the entry, I need to check in this entry if there are valid numbers and print them at the end of…
-
3
votes1
answer92
viewsDoubt about Python classes and attributes
I have a question about classes, attributes and objects in Python. For example using the class below: class Car: drivers = ['João', 'José'] def allowed_drivers(self): print('The list of allowed…
-
3
votes3
answers503
viewsCombination of values for sample selection
Guys, I’m having difficulties to finish a job and would like help. Anyway, below is the excerpt from my list.csv: n,NOME,COR,VALOR 1,Lapis ,Verde,"11,1" 2,Caneta ,Vermelho,"12,25" 3,Lapiseira…
pythonasked 5 years, 7 months ago Marcelo João 33 -
3
votes2
answers53582
viewsAccess to Xmlhttprequest has been blocked by CORS policy
I have two Flask applications running locally on my machine. One is running on port 5000 and the other on port 5050. I need to make a 5000 app call to 5050. But I’m having this problem: Access to…
-
3
votes1
answer186
viewsPython Machine Learning to Predict Multiple Choice Quiz Template
I got the templates from the last five contests at an exam stand. Templates of multiple choice (A,B,C,D,E). Let’s imagine that the test only has 5 questions, whose templates are: q1 q2 q3 q4 q5…
-
3
votes2
answers723
viewsMethod "Sort" returning only "None", what is the reason?
I’m solving a problem in Python 3, about lists. Part of my solution involves sorting a list of values float, I decided to use the method sort. This method should return the already ordered list in…
-
3
votes4
answers1041
viewsDoubt Exercise Python
The challenge is: Write a program that receives as inputs (use the input function) two integers corresponding to the width and height of a rectangle, respectively. The program must print a string…
-
3
votes1
answer157
viewsRunning functions simultaneously in Python3
I have a snippet of a code that performs "text to Speech", but to see the print() function I have to wait for the playsound() function to end. Is there any way to make the script run the print()…
-
3
votes1
answer50
viewsWhy is it wrong for the file to be closed if in each iteration it should open again?
I’m trying to make a code so that on my Youtube playlist. The program compares if the link of such a playlist video is included in a txt file. If it is, it does not download the video, if it is not,…
-
3
votes1
answer524
viewsHow to insert animated gif into pygame
Good afternoon, I’m doing a college job, it’s a python game and I need to insert a gif in the code but when I use the command pygame.image.load("correr.gif") it shows the image of the gif frozen,…
-
3
votes3
answers3895
viewsPython date validation (tests)
I am trying to do a date validation with Python. My exercise asks for the validation of months with 31 days and leap year. def data_valida(data): #Valida data. Recebe uma string no formato…
-
3
votes2
answers71
viewsAllocation of values other than normal
def testes(x, y): while y: x, y = y, x % y return x I don’t understand this part of the code, what happens with the 'x' and the 'y' on the left side of the equals sign and what the 'y' does on the…
-
3
votes1
answer85
viewsWhy does x += y add the values in an iteration?
I don’t understand why this code r += v sum the values. I would like someone to explain to me why the output of this code: for c in range (0, 10): v = int(input("numero: ")) r += v…
-
3
votes2
answers1055
viewsElaboration of cipher in python
Hey, guys, I’m new here and in the programming world, so any criticism is welcome. I have a problem with this cesar cipher I’ve been trying to do. They could point out possible errors, and ways to…
-
3
votes2
answers239
viewsWhat is the difference between ", " and "+" in Python?
In a code mensagem = "ola " nome = input("Diga seu nome ") print (mensagem + nome ) mensagem = "ola" nome = input("Diga seu nome ") print (mensagem , nome ) The two do the same function , with the…
-
3
votes1
answer62
viewsHow does this piece of code work?
My doubt is more precisely in line "8", line containing the for. I’ve never seen one used this way. I understood the logic of the line, but the operation of this iteration made me very curious.…
-
3
votes2
answers81
viewsHow to sort a string by initial fragment?
I need to order a string originating from the git tag -ln. 2019.3.0 Primeira versão totamente integrada com gitlab-ci 2019.3.0-dev0 Aplicado correções sugeridas por py3kwarn 2019.3.0-dev1 refatorado…
-
3
votes1
answer427
viewsPython - Run the next command without waiting for the end of the first
Good evening, everyone. I have the following function to create a bar Progress: def progress_bar(p_value, p_max: int): """ :70 = É o tamanho da barra :param p_value: Valor que está sendo iterado de…
pythonasked 5 years, 6 months ago Cleber Nandi 137 -
3
votes4
answers1053
viewsPython Queue Code - How to check if there is an element with a specific name in the queue and its index position?
I’m making a queue code from a bank where you need to type the name, age, weight and gender class Person and class Queue and this code has some options that must be entered according to the user’s…
-
3
votes3
answers230
viewsRemove lowercase letters from a list
I was trying to make a program that could identify whether a letter is in upper case or in Lower case in a list, so that it would delete the lower case letters. frase = ("A B C D e f g h") new =…
-
3
votes3
answers133
viewsRound Decimal
Dear gentlemen I’m doubtful of rounding in python. I know, for example, that if I have a variable like this,: n=2.23445 print (f'o valor de n é {n:.2f}) will print 2.23 But in the case of a list?…
pythonasked 4 years, 3 months ago user201087 -
3
votes2
answers272
viewsFunction that compares characters from a string and returns true or false
I’m trying to make a function that should return true or false if the first and last characters are equal. However, comparing them is giving error of out of range and I can’t identify the reason:…
-
3
votes1
answer183
viewsIs it possible to define async as the initializer method of a Python class?
Let’s say I have a class where I need to initialize a field with the return of a corotina: import asyncio class Server: def __init__(self): self.connection = await self.connect() async def…
-
3
votes1
answer555
viewsProblems with Python3 in connection with Firebird2.5
I made this Python code (basic connection with Firebird): import fdb con = fdb.connect( host='192.168.1.17', database='/home/firebird/questor.fdb', user='sysdba', password='masterkey' ) cur =…
-
3
votes1
answer171
viewsPython isset check (details)
My question is this, in PHP I have a code curl that returns some json as you can see in the code: $response = curl_exec($request); $header_size = curl_getinfo($request, CURLINFO_HEADER_SIZE);…