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
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 160 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Remove specific elements from list with a pattern Xalagy 3 289 Oct-11-2020, 07:18 AM
Last Post: Xalagy
  How to remove char from string?? ridgerunnersjw 2 111 Sep-30-2020, 03:49 PM
Last Post: ridgerunnersjw
  How to remove dict from a list? Denial 7 229 Sep-28-2020, 02:40 PM
Last Post: perfringo
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 305 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  taking input doesnt print as list bntayfur 2 320 Jun-04-2020, 02:48 AM
Last Post: bntayfur
  Remove from end of string up to and including some character lbtdne 2 445 May-17-2020, 09:24 AM
Last Post: menator01
  Remove escape characters / Unicode characters from string DreamingInsanity 5 828 May-15-2020, 01:37 PM
Last Post: snippsat
  Remove all \n from end of list items JackMack118 4 24,596 Dec-27-2019, 08:34 AM
Last Post: perfringo
  Highlight and remove specific string of text itsalmade 5 677 Dec-11-2019, 11:58 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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