![]() |
List Syntax - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: List Syntax (/thread-27061.html) |
List Syntax - Hitso - May-24-2020 Pls help, what I am doing wrong ? I'm not getting any output, whereas I'm expecting it to return as String 2 list1 = ["String1", "String2", "String3"] list1[2] RE: List Syntax - michael1789 - May-24-2020 (May-24-2020, 06:42 PM)Hitso Wrote: Pls help, what I am doing wrong ? I'm not getting any output, whereas I'm expecting it to return as You aren't doing anything with list1[2] .You need to print it print(list1[2] ).
RE: List Syntax - menator01 - May-24-2020 As a side note list1 = ["String1", "String2", "String3"] list1[2]will not return string2 but will return string3. index starts at zero RE: List Syntax - DPaul - May-25-2020 Hi, If you type this in the shell editor, it will, as expected, output "String3". As a saved "*.py' file, you will need a print() statement as stated above. Paul RE: List Syntax - hussainmujtaba - May-26-2020 To get string 2 as output, the code should be print(list1[1])Note the index start from zero.Also you don't need print function when using Jupiter notebook.But incase of python editors, you need to use print function to print anything |