If Statement Python – CBSE Class 12
If Statement in Python
The simplest form of the if statement python tests a condition and check if the condition evaluates to true then it carries out some instructions otherwise and if the condition is false then it does nothing.
In general form its syntax is shown below figure.
if<conditional expression>:
statement 1
statement 2
————-
————-
Where statement may be a single statement, a compound statement or just a pass statement.
Example –
ch= input (“Enter a character”)
If ch>=0 and ch<=9:
Print (“you have entered a digit”)
After getting input in Ch. the above code compares the value of Ch. if value of Ch. falls between the character 0-9, the condition evaluates to True, then it will execute statements in the if-body that means it will print the message saying “you have entered a digit”
Similarly, let’s have an another example for more understanding
ch=input (“please enter a character”)
If ch == ” ” :
Print (“you have entered a space”)
If ch>=’0’ and ch<=’9’
Print (“you have entered a digit”)
Read carefully the above code example and try to find out the result yourself.
Now have a look in some other examples of conditional expression in if statement.
If marks >=90:
Print (“you did very well”)
If a>b:
Print (“a is bigger than b”)
If x:
Print (“x has truth value as true”)
Why if statement in Python?
In this tutorial, we have learnt about if statement in python for CBSE class 11 & 12 and its related concepts according to CBSE syllabus and this tutorial is useful for Central Board of Secondary Education (CBSE) student of class 11th and 12th , who opted computer science (Code 083) as an optional subject. This topic is also very important to start learning python programing language for beginners of class 11th and 12th.
You can check the latest CBSE syllabus for computer science Click here for syllabus OR Click here
UNIT NO. | UNIT NAME | MARKS |
1 | Computational thinking and programming | 40 |
2 | Computer network | 10 |
3 | Database management | 20 |
4 | Practical | 30 |
5 | Total | 100 |
Unit II: Computational Thinking and Programming – 1
According to the syllabus , Unit II Computational Thinking and Programming – 1 has the above concepts for learning related to python Bitwise Operators in Python.