Ask coding questions

← Back to all posts
how do you do an if statement with python
dragonhunter630

how do you do an if statement with python

Voters
LUISRODRIGUEZ27
Bcoleman035
DavionGatlin
RobertoBean
awsomewasd
dragonhunter630
Comments
hotnewtop
RobertoBean

To elaborate, let's try an example.

That's not all you can do though.
Here's all the comparisons that you can do in example form:

Those are at least all that I know, someone let me know if I missed any.

You also have modifiers you can put before and inbetween conditions, those are
and, not, and or

To show how to use these and what they do, here's an example:

We also have one more thing we can do with if-else. We also have if-elif-else in python as well.

Python sees if the if statement is true, and if it is, executes it. Otherwise, it executes the elif statement, then if that's not true, it executes the else statement.

To make some more sense out of it,

Is the same as;

You can also have mutliple elifs following an if.

I hope this made some sense and helped you out!

TimothyAnderso1

Just to make it more simple:

Also it dont matter if you use "These" for a string or 'These' Its the same

ArchieMaclean

@TimothyAnderso1 That's simpler probably

but it should have a lowercase if.

TimothyAnderso1
ArchieMaclean

@TimothyAnderso1 You weren't originally?

ArchieMaclean

Like this:

You can add as many elif statements as you want.

Please mark this as the answer if it solved your problem :)

ArchieMaclean

@ArchieMaclean you can replace something and somethingelse with any comparison, e.g.

AidenTV1

not working for me