-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifelse.txt
More file actions
37 lines (32 loc) · 1.27 KB
/
ifelse.txt
File metadata and controls
37 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if else
which is used for conditional statement which meaning is same as if else in c,c++,java
syntax of if else
Python relies on indentation (whitespace at the beginning of a line) to define scope in the code.indentation is some specific space in all statement Other programming languages often use curly-brackets for this purpose.like c,c++,java
but in python if you define the if else you used simalar space in all statement
when we use two if for number to find odd even when we run debugger we se the compiler check for both if wheter first if condiftion is true or not that is why we use else to increase efficiency when if conditon is not true it execute the statement of else without checking
a=5
if a%2==0:
print("even")
else:
print("odd")
we can also create nested if else we can check using indentaion
a=2
if a%2==0:
print("even")
if a>4:
print('number is greater than 4')
else:
print('number is not greater than 4')
else:
print("odd")
elif keyword
"if the previous conditions were not true, then try this condition" if it is wrong then it only check for next confiditon
a=8
if a==1:
print("a=1")
elif a==2:
print("a=2")
elif a==3:
print("a=3")
else:
print("no one")