Python Forum
with input remove a string from the list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
with input remove a string from the list
#1
Hello,

i cant quite figure why this code doesnt work Wall

friends = ["Kevin", "Karen", "jim", "Oscar", "Toby"]
variable = input("Delete Kevin? ")
if variable = yes:
    friends.remove("Kevin")
print(friends)
Reply
#2
if variable = yes:
input returns a string, compare to a string of 'yes'
if variable = 'yes':
Reply
#3
= is assignment
== is equality
You need to use the second one

then you will get another error
because at the moment yes is a variable and is not defined. You want it to be string in order to compare with the user input
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
thanks a lot!

especialy your explanation helped my a lot buran!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  remove gilberishs from a "string" kucingkembar 2 202 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  difference between forms of input a list to function akbarza 6 928 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  unable to remove all elements from list based on a condition sg_python 3 371 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Using string input for boolean tronic72 3 634 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  user input values into list of lists tauros73 3 1,023 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,251 Nov-13-2022, 01:27 AM
Last Post: menator01
Smile please help me remove error for string.strip() jamie_01 3 1,149 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  Remove a space between a string and variable in print sie 5 1,706 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  How do I remove spurious "." from a string? Zuhan 7 1,962 Apr-12-2022, 02:06 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020