Skip to main content

All Questions

Tagged with
-3 votes
1 answer
77 views

Could you please explain below three codes?, why they are giving different results

code 1 list_a = [] list_a += str(1) O/P: ['1'] code 2 list_a = [] list_a += 1 O/P: Type Error code 3 list_a = [] list_a = list_a + str(1) O/P: Type Error I'm expecting that if += operator ...
Bhuvana ravula's user avatar
1 vote
0 answers
17 views

What does the operator id() return in Python3? [duplicate]

Program: a = 5 b = 5 print(a == b) print(id(a) == id(b)) Output: True True I understand the first line of the output should be True, but why is the second line also True? Doesn't the operator id() ...
Timothty C.'s user avatar
-1 votes
3 answers
126 views

Using multipe operators in Python sequentially

I'm trying to understand how Python handles using multiple sequential operators to add and subtract numbers. Here is an example of what I mean: >>> 5+-2 3 >>> 5-+2 3 >>> 5+-+...
Dušan Stokić's user avatar
1 vote
1 answer
110 views

How to overload the add operator to return the length of two string when they are added?

I am trying to create a class diffStr that behaves like str except, when a user tries to add or multiply two strings, the output is the length of each string added or multiplied (respectively). My ...
Harsh Darji's user avatar
0 votes
4 answers
126 views

Python script that increases a number by a percent and then with a new number till goal

I found this problem and wanted to try to execute, but got stuck: Compile a program that allows you to determine how many days will be enough for 200 something if consumed on the first day 5 tons, but ...
Pmileika's user avatar
1 vote
4 answers
75 views

Can anyone explain how to solve this problem

A program that reads 3 numbers A, B and C and checks if each 3 numbers are greater than or equal to 20. Output should be single line containing a boolean. True should be printed if each number is ...
Laxman Donthula's user avatar
1 vote
3 answers
453 views

compare two attribute of objects from different list of object python

I'm still pretty new to python and oop and I have some struggles resolving this problem without breaking the performance. I want to compare the id of my user (that's what I have done with the eq ...
bakelue's user avatar
  • 25
-1 votes
2 answers
802 views

What is the difference between the operator acting elementwise vs on the matrix using Numpy?

Numpy docs talks about the difference between the product operator and the matrix operator. Unlike in many matrix languages, the product operator * operates elementwise in NumPy arrays. The matrix ...
Tim's user avatar
  • 1,796
1 vote
2 answers
49 views

Contiguous operators in Python raises no error

Accidentally, I typed multiple contiguous + operators and it ran successfully. This is what I did 2 ++ 3 // returns 5 Then i tried multiple combinations and it actually executes only the last ...
targhs's user avatar
  • 1,667
-4 votes
1 answer
45 views

Cannot understand how following sample code works

['f', 't'][bool('spam')] this gives result , 't' But I cannot understand how this sample of code works?
nppn's user avatar
  • 3
-2 votes
4 answers
49 views

How to do this without double operators?

I was trying to print some numbers within a certain range horizontally using for loop with double operators(+=) str_1='' for i in range(10): str_1 += str(i)+" " print(str_1) The ...
Niloy_Codes's user avatar
1 vote
1 answer
68 views

The order of operations in Python [duplicate]

I'm trying to understand the order of operators in Python. I tried the following: var1 = None var2 = 0 print( (var1 is None) != var2 ) print( (var1 is None) != var2 is True ) ### print( ((var1 is ...
lay's user avatar
  • 11
0 votes
1 answer
77 views

equal operator is not operating the way it should Python

I am currently trying to write an script which is checking if the current date and time is equal to a date and time in a file. But for some weird reason my main if statement is only being triggered ...
Scripter1's user avatar
0 votes
1 answer
252 views

Confused with greater than and less than operators

I'm new to coding and I'm learning how to code in python. What I can't get my head around is why the '<' is read as '>' when a number comes before it. e.g. if 4 < people <=14: print('...
Shakur's user avatar
  • 1
-5 votes
2 answers
382 views

How to divide a number by 10 only in Python? [closed]

I just need to divide some number by only 10. For instance, if the number is 127, the result should only be 12 and remained to be 7. Is there a way I can get Python to give me these BOTH results? ...
Black's user avatar
  • 11

15 30 50 per page
1
2 3 4 5
10