Comments & if else statement in python
Till now we have seen how to create a python script file and execute it.
In this post, we will look how to include comments in the script and how to use if else statement.
To understand this create below python script.
Comments & if else in Python Script
user@ngelinux$ cat third.py #!/usr/bin/python ### This is a comment ### In python comments start from hash sign print('Verify if you are eligible for voting...') age=int(input('Please enter your age')) ### condition always start with intended block in python ### We use colon in if else statement in python if (age>18): print('You are eligible to vote') else: print('You are not eligible to vote');
Execution of the script
user@ngelinux$ ./third.py Verify if you are eligible for voting... Please enter your age4 You are not eligible to vote user@ngelinux$ ./third.py Verify if you are eligible for voting... Please enter your age23 You are eligible to vote 01HW860264:python saket1447583$
In this fourth article of learning python, we have seen how to use if else in python and how to input comments in the shell script.