+ 2

new to python can someone help

So I began to learn Python on Tuesday. I still can't wrap my mind around the elif command, I can understand basic if x happens or if x doesn't happen then execute a command, and else is just a way of saying if the IF statement doesn't happen then else is saying 'execute this instead' so its the combination of else and if that confuses me and wouldnt it be ifel not elif? I must be overthinking this

9th Sep 2017, 10:31 AM
Leeroy
10 Answers
+ 14
over thinking. it is simply because it is easier to read nested if statements. ifel would easily be mistaken for an if especially in a large code base. not only it makes more sense when you say it. if this equals that then { do this} elseif this equals thatotherthing then { do that}. versus if this equals that then { do this} if else this equals that other thing then {do that }
9th Sep 2017, 10:43 AM
jay
jay - avatar
+ 12
in your second example the computer has to check each if value for correctness. with elif when the first match is found the rest are not executed
9th Sep 2017, 11:02 AM
jay
jay - avatar
+ 12
that and you could also possibly get into a situation where a variable matches one or more if statements.
9th Sep 2017, 11:13 AM
jay
jay - avatar
+ 3
It is easy. Probably after some lessons in https://www.sololearn.com/Course/JUMP_LINK__&&__Python__&&__JUMP_LINK/?ref=app you will get the hang
9th Sep 2017, 11:37 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Do you mean it's easier to read THAN nested if statements @Jay?, Does it just mean that its another way of executing an If command in a convenient manner? Because for some examples i've seen people say: if expression1: statement(s) elif expression2: statement(s) elif expression3: statement(s) else: statement(s) Whatd be the difference from just typing: if expression1: statement(s) if expression2: statement(s) if expression3: statement(s) else: statement(s) It actually seems more convenient to just use 3 if statements, or does this syntax appear as invalid or something?
9th Sep 2017, 10:57 AM
Leeroy
+ 2
So its just a way of cutting down the necessary procesing power of your computer whilst it runs your script?
9th Sep 2017, 11:07 AM
Leeroy
+ 2
Thanks dude this has helped
9th Sep 2017, 11:17 AM
Leeroy
+ 1
A while ago i started learning python and i couldn't rap my head around everything either. I suggest before you continue with python, learn something like HTML, because even though it is no the same type of code, (HTML uses tags rather than scripts or commands) it is simple and helps u get a better grasp of code and how it works. Hope this helps ;) #KeepOnCoding
9th Sep 2017, 10:39 AM
The Lemon Crafter
The Lemon Crafter - avatar
+ 1
Its a module for college sadly, thrown into the deep end! Gotta get my head wrapped around the terminology before I know how to apply it 💡
9th Sep 2017, 10:41 AM
Leeroy
+ 1
Ah i see now sorry XD. I found a comment with links to a pdf collection that has python on it, it might help: https://www.sololearn.com/Discuss/510275/ultimate-pdf-collection-for-learn-programming Also i suggest just searching up anything u have trouble with, i found lots of other helpful websites that have made it easier to understand some bits of code. Good luck bro! ;)
9th Sep 2017, 10:49 AM
The Lemon Crafter
The Lemon Crafter - avatar