Getting Started With Python Programming (Part 1)
Getting Started With Python Programming (Part 1)
In the code given on the left hand side, there are 3 variables.
One more thing to note in the above program code is the heading of the program, which is enclosed in triple
quotes (‘’’). These statements which are enclosed in triple quotes are called comments. When the program
is run, these statements are ignored by the compiler/interpreter. These statements are basically given for
the ease of programmer.
WORKING WITH ITERATIVE STATEMENTS (loop)
Iterative statements means writing statements under iteration (loop). This means that the statement which
is/are given under iteration are repeated as per the given values in the range.
There are 3 components of a range:
Start: The value from where loop initializes.
Stop: The value upto which the loop iterates. It is always 1 step less than the given value.
Step: The value which defines the number of jumps taken by the loop.
There are 2 types of loops in Python, for loop and while loop.
In the code given on the LHS, for loop is incorporated with loop
variable as i and range from 5 to 16.
As per the explanation given above the start value is 5, stop value is 16
which will terminate at 15 (one step prior) and the step value is 1.
Please note that a colon (:) sign is given after the for statement and
with this the next statement (print) is coming as indented.
The loop variable (i) is given in the print statement with end=”,”. By this
the output will come in a single horizontal line separated with commas.
This example is same as the previous one. The only difference is that,
here start value and stop values are given but step value is missing.
Please note,
In case, the step value is not given, it is taken as 1 by default.
This example is also same as the previous two examples. The only
difference is that, here the step value is given as 3. So, the output will
come from 5 skipping 2 values in each iteration.
Please note,
In this example, the loop is terminated at 14. Skipping 2 steps.
This example is also same as the previous two examples. The only
difference is that, here the step value is given as 3. So, the output will
come from 5 skipping 2 values in each iteration.
Please note,
In this example, the loop is terminated at 14. Skipping 2 steps.
Program to ask the user enter any string and display the number of UPPERCASE letters, LOWERCASE letters,
DIGITS and SPECIAL characters.
Program to ask the user enter any string and display the string with all the letters in their reverse case,
using built-in functions. (Uppercase letters to lowercase and vice-versa.)