Public Group

# Python 3 Questions

This topic is 2072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is just a list of random questions I asked myself while looking at a python tutorial on Youtube.

Are lists with just strings always mutable lists?

Are lists with integers always immutable?

Mutable implies you can do something to "mutate" it or something. What would that be?

Naming a range for a variable results in it not listing the last number "201" in the shell. Why is this?
Why do you have to put "[:]" before stating a range value?
listCycle[:] = range(1,201)

I know you can type;
for i in listCycle:
if (1%2) == 0
continue
else:
print(i)
to only display the odd numbers. How would you display only even numbers?

##### Share on other sites

I don't know most of these (I don't use Python), but I can answer the odd/even numbers question.

I'll be assuming you meant if (i % 2) == 0, not if (1 % 2) == 0.

The % operator is called modulo. It returns the remainder of a division between the parameters on either side (left parameter divided by right). 3 % 2 is equal to 1, because 3 / 2 leaves 1 as a remainder.

If we modulo with 2 and check if it's equal to 0, that means the division with 2 has no remainder, which is the case for all even numbers.

The "continue" command that is triggered if this occurs makes the for loop skip through to the next iteration of the loop. In the code snippet you posted, all even numbers (which are perfectly divisible by 2) will just skip to the next iteration, without doing anything else.

So, if you want to print even numbers instead, you can simply swap the if (i % 2) == 0 to if (i % 2) == 1.

Edited by Lactose™

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!