close

How to use a for Loop for Multiple Variables in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about How to use a for Loop for Multiple Variables in Python. so without wasting time lets learn about of this.

How to use a for Loop for Multiple Variables in Python

  1. use a for Loop for Multiple Variables in Python

    to use a for Loop for Multiple Variables in Python just Use zip().By using zip() you can use a for Loop for Multiple Variables in Python. Lets learn about of this by given below example: students = ["heeya", "meet", "jaydeep"] marks = [95,98,88] for marks, students in zip(students, marks): print(f"{marks} gets {students} marks") Output : heeya gets 95 marks meet gets 98 marks jaydeep gets 88 marks

  2. How to use a for Loop for Multiple Variables in Python

    to use a for Loop for Multiple Variables in Python just Use enumerate().By using enumerate() you can use a for Loop for Multiple Variables in Python. Lets learn about of this by given below example: students = ["heeya", "meet", "jaydeep"] marks = [95,98,88] for i, student in enumerate(students): mark = marks[i] print(f"{student} gets {mark} marks") Output : heeya gets 95 marks meet gets 98 marks jaydeep gets 88 marks

  3. python for loop multiple variables

    To use a for Loop for Multiple Variables in Python just Use enumerate().By using enumerate() you can use a for Loop for Multiple Variables in Python. Lets learn about of this by given below example: students = ["heeya", "meet", "jaydeep"] marks = [95,98,88] for i, student in enumerate(students): mark = marks[i] print(f"{student} gets {mark} marks") Output : heeya gets 95 marks meet gets 98 marks jaydeep gets 88 marks

Method 1: Use zip()

By using zip() you can use a for Loop. Lets learn about of this by given below example:

students = ["heeya", "meet", "jaydeep"]
marks = [95,98,88]
for marks, students in zip(students, marks):
    print(f"{marks} gets {students} marks")

Output :

heeya gets 95 marks
meet gets 98 marks
jaydeep gets 88 marks

Method 2: Use enumerate()

By using enumerate() you can use a for Loop for Multiple Variables. Lets learn about of this by given below example:

students = ["heeya", "meet", "jaydeep"]
marks = [95,98,88]
for i, student in enumerate(students):
    mark = marks[i]
    print(f"{student} gets {mark} marks")

Output :

heeya gets 95 marks
meet gets 98 marks
jaydeep gets 88 marks

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment