May-19-2023, 03:59 PM
Hello everyone, I was testing out making a f strings with parts of a list, and after experimenting a lot, I figured out how to make it work but I am confused why:
#contains a different message for each portion of the list. distros = ['Ubuntu','Mint','Kali','Fedora','CentOS','Oracle','Mageia',\ 'KateOS','Slackintosh'] for debian in distros[:3]: print(f"{debian} is a debian distribution.") for Red_Hat in distros[3:6]: print(f"{Red_Hat} is a Red Hat distribution.") for slackware in distros[6:]: print(f"{slackware} is a slackware distribution.")That gives me the proper output:
Ubuntu is a debian distribution. Mint is a debian distribution. Kali is a debian distribution. Fedora is a Red Hat distribution. CentOS is a Red Hat distribution. Oracle is a Red Hat distribution. Mageia is a slackware distribution. KateOS is a slackware distribution. Slackintosh is a slackware distribution.but I am confused why I am using repeating numbers in the above code to accomplish that: for the Red Hat distributions, why am I starting with 3 even though the last cycle ended with 3, and then with the slackware distributions, why am i starting with 6 even though the last cycle ended with 6? To me, the last two should be [4:6] and [7:9}, but that gives me incorrect results.