Whats the output of "for i in "hello world": print(i)" and why/how is this achieved

output is: "h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d" each character being printed in a new lineA "for" loop is used to itterate over a string "hello world" and print each character, this works by "moving" variable "i" along the string, giving it a different character per every iteration of a loop and then asking to print the value its currently holding

Answered by Python tutor

2189 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Create a program that generates prime numbers between two integer boundareis


What built-in types does python provide?


Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour


What is the outcome of the following code? print(2*[3,4,5])


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences