I have two lists.
SpeedList = ["25","30"]
NameList = ["John Smith","Tom Smith"]
..And I want to print each element of each list together on one line. So it will say something along the lines of John Smith was driving at 25 mph
And Tom Smith was driving at 30 mph
on a second line.
I've tried:
print (NameList)," Was driving at ",(SpeedList), " mph."
But it prints:
['John Smith', 'Tom Smith'] Was driving at ['25', '30'] mph.
Like this?
>>> SpeedList = ["25","30"]
>>> NameList = ["John Smith","Tom Smith"]
>>> for name, speed in zip(NameList, SpeedList):
... print (name)," Was driving at ",(speed), " mph."
...
John Smith Was driving at 25 mph.
Tom Smith Was driving at 30 mph.
>>>
name=["John Smith", "Tom Smith"]
speed=["25", "30"]
for i in range(2):
e=name[i]
f=speed[i]
result=e + " was driving at " + f + "mph."
print result
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.