Python Forum
question on list in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question on list in Python
#1
Hello,
Can you please explain to me in simple lines, the difference between "a = list("apple)" and "a = ["apple"]"?
Actually I was trying to append the character '_' to every character I find in the list.

WordToBeGuessed = ["Apple"]
Hidden = []
for EachCharacter in WordToBeGuessed:
    Hidden.append("_")
print(WordToBeGuessed)
print(Hidden)
gives me ['_']

while

WordToBeGuessed = list("Apple")
Hidden = []
for EachCharacter in WordToBeGuessed:
    Hidden.append("_")
print(WordToBeGuessed)
print(Hidden)
gives me ['_', '_', '_', '_', '_']

which is the desired answer but I just wanted to know the difference. Thank You
Reply


Messages In This Thread
question on list in Python - by spalisetty06 - Jun-30-2020, 08:58 AM
RE: question on list in Python - by pyzyx3qwerty - Jun-30-2020, 09:03 AM

Forum Jump:

User Panel Messages

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