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
  Creating new column with a input string drunkenneo 2 468 Apr-14-2021, 08:10 AM
Last Post: drunkenneo
  User input/picking from a list AnunnakiKungFu 2 542 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
  .remove() from a list - request for explanation InputOutput007 3 558 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  Remove double quotes from the list ? PythonDev 22 2,264 Nov-05-2020, 04:53 PM
Last Post: snippsat
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 705 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Remove specific elements from list with a pattern Xalagy 3 778 Oct-11-2020, 07:18 AM
Last Post: Xalagy
  How to remove char from string?? ridgerunnersjw 2 578 Sep-30-2020, 03:49 PM
Last Post: ridgerunnersjw
  How to remove dict from a list? Denial 7 800 Sep-28-2020, 02:40 PM
Last Post: perfringo
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 845 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  taking input doesnt print as list bntayfur 2 677 Jun-04-2020, 02:48 AM
Last Post: bntayfur

Forum Jump:

User Panel Messages

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