FUNCTIONS

Hello programmers! Have you ever seen some fruitful things in programming languages? I guess not! So, let’s discuss today about FRUCTIFEROUS FUNCTIONS which are going to benefit you in many ways and are really worthy!

Defining any functions are the core of the protractile programming. Python allows mandatory arguments, keywords, etc, to be defined in a function.

WHAT ARE FRUCTIFEROUS FUNCTIONS?

Functions are basically blocks of code which performs certain particular sort of application or task as per given in code.

It makes our code reusable. Functions are required because they reduce the redundancy in our program and they increase the readability.

Basically, functions are divided into two following types:

BUILT-IN FUNCTIONS

These functions are built into python and they can be called directly.

USER-DEFINED FUNCTIONS

These functions are made by Users and then they can be used and called anytime.

Let’s understand how to define a function in Python:

1. Function always begin with the keyword def and followed by parenthesis “()”.

2. You can input any type of arguments or parameters within the parenthesis.

3. The first statement of the function is optional. That means; it is docstring or documentation string which is a string literal.

4. The statements/code within the function are always indented and starts with a colon “:”.

5. At last; the return statement is written to return some value or expression.

Syntax:  def name_of_function(any_no_of_parameters):

                    “docstring_of_fucntion”

                     code_of_function

                     return (expression)

You all now might be thinking that after defining function, how we can use it in the program? Right?

Don’t worry! Let’s see that a function can be called after defining in the program.

How to call a function?

Once you have defined function, you can execute it in the program by calling it. You can directly call a function from python prompt or you can call it from another function. Let’s see an example of how to call a function: function.py

In this way, you can define and call a function easily in python and it can used as many times as you want. Let’s wrap it up to here. Tomorrow, we’ll further see that how to input various parameters, pass by value, pass by reference, etc. in a function. Practice it well! Have a great one, all!

PYTHON STATEMENTS (FLOW CONTROL PART-3)

Hello fellow programmers! I’m again back with Basics Of Python. Today, we’re going to learn about various types of statements which are used in python for different purposes.

Sometimes, you all might face a situation in which you need to skip some part of the loop and start next execution or you want to exit completely from the loop after some executions. So, for these; python has provided the break, pass and continue statements to handle that type of situations whenever occurred. So, let’s discuss it in detail and understand the fundamentals.

BREAK STATEMENT:

The break statement terminates the loop when a certain condition/expression is satisfied and moves to next iterations which are to be executed outside the loop. It brings the program control out of the loop. The break statement is used with for loop, while loop, if statement, etc.

Syntax: a) in for loop:

              for value in lists:

                  if expression:

                      break

              b) in while loop:

              while expression:

                  if expression:

                      break

CONTINUE STATEMENT:

 The continue statement is used inside a certain loop to skip the rest of the statements in the body of the loop for the current iteration and returns the control to the beginning of the loop. The continue statement doesn’t terminate the loop but jumps to next iteration which is to be executed.

Syntax: a) in for loop:

              for value in lists:

                  if expression:

                      continue

              b) in while loop:

              while expression:

                  if expression:

                      continue

PASS STATEMENT:

The pass statement is a null operation. That means, nothing happens when it executes. It is used when you don’t want any code to execute further in the loop.

Syntax: a) in for loop:

              for value in lists:

                  if expression:

                      pass

              b) in while loop:

              while expression:

                  if expression:

                      pass

Let’s jump on the program of python which uses these statements: statements.py

It feels really good to practice python regularly. I hope that you all are following the same. Consistent practice and focus will surely carve you as a true Pythonain. So, we’ll meet soon with next topic from our Python Basics. Till then; have a great one people!

~ITERABLES and SEQUENCES~

Anything that can be looped over with a for loop is called as an ITERABLE.

Eg: for element in iterable:

print(element)

SEQUENCES are iterables that have some specific set of features. They contain indexing. They start from 0 and end at (n-1) in which ‘n’ is length of the sequence. Examples of sequence are Lists, Tuples, etc. They all work in this way.

Eg: string= “We The Pythonians”

Thus, in Python; anything that can be looped over for loop is known as an “Iterable” and “Sequences” are one type of iterables.

~We The Pythonians~

LOOPS (FLOW CONTROL PART-2)

Hello programmers! I’m back with Basic of Python.

Let’s continue to study our Flow Control (part-2) which is LOOPS.

Python provides three ways of executing complex conditions in form of loops. They are:

Type of LOOPDescription
for loopIt executes statements multiple times and reduces the code that manages the variable of loop.
while loopIt is used to iterate over a block of code until the given expression or condition is TRUE.
nested loopUsing of one or many loops inside a loop which can be any type that is for, while, etc.

1. for loop:

For loop in python is generally used to iterate over a sequence. Sequence includes strings, tuples, dictionaries, etc.

Sometimes for loop includes three parts: a) Initialization b) Condition c) increment/decrement

For loops are used whenever user wants to know how many times he/she has to execute certain set of statements.

Syntax: for variable in sequence:

                  {statement/code}

2. while loop:

Using while loop, user can execute certain set of statements as long as the condition given evaluates to be True.

While loop generally do the condition updation to terminate the loop.

User is given option to explicitly chase conditions inside to terminate loop.

Syntax: while expression:

                   {statement/code}

3. nested loops:

Nested loops generally means to use a loop in another loop. Python allows the use of one loop inside another loop.

Syntax: a) [nested for loop]

for variable in expression:

    for variable in expression:

        {statement/code}

    {statement/code}

b) [nested while loop]

while expression:

    while expression:

        {statement/code}

    {statement/code}

Let’s have a quick eye on the program of loops: loops.py

So, today we learned about basic introduction to loops. In next posts, we’ll learn about various statements used in loops to terminate/continue programs after satisfying some conditions. So, concentrate well and practice more to get perfect in Python. Have a great day!

DECISION MAKING STATEMENTS (FLOW CONTROL PART-1)

Decision Making—It is the outlook of conditions which are occurring during the execution of the program provided by specified actions taken according to the conditions.

The structures used for Decision Making are called Decision Structures. Decision Structures evaluate the multiple conditions or expressions which gives us the output TRUE or FALSE.

In Python, non-zero and non-null values are considered as True and zero and null values are considered as False.

Python has 4 types of Decision-Making Statements. They are as follows:

Conditional StatementsDescription
if statementIt contains expressions which can be followed by one or more statements.
if…else statementIt contains else statement with if statement; when condition isn’t satisfied then else statement is executed.
nested if statementsIt contains if statements under main if statements; nested part is executed when first if statement evaluates to be True.
if…elif…else statementsIt contains multiple expressions; when if statement isn’t satisfied then control goes to elif statement and if the condition evaluates to be False the control goes on else statement.

1. If Statement:

If statement contains condition or logical expression which is being evaluated or compared and decision is made based on the evaluation. If the expression evaluates to be true then the code under If statement is executed otherwise the end of block is executed.

Syntax: if expression:

                  {statement/code}

2. If…else Statement:

In if…else statement; when the expression in if is not evaluated to be True then the pointer gives access to else statement which resolves to False and the statement in it is executed.

Syntax: if expression:

                  {statement/code}

              else:

                  {statement/code}

3. If…elif…else Statements:

The elif statement is used to check multiple expressions for True and the code/statement is executed if any expression among them evaluates to be True; otherwise else statement will be executed which will resolve the result to be False.

The elif statement is optional. Multiple elif statements can be present for one if statement in one program but only one else statement should be present for one if statement in every program.

Syntax: if expression:

                  {statement/code}

              elif expression1:

                  {statement/code}

              elif expression2:

                  {statement/code}

              …….

              elif expression(n):

                  {statement/code}

             else:

                  {statement/code}

4. Nested If Statements:

Sometimes a situation can be occurred when user wants to check a condition under a condition which resolves to be True. In such case, nested if statements are used.

In nested if statements, user can have if statements under if statements, if..else statements under if…else statements, or if…elif…else statements under if…elif…else statements.

The nested part is executed if the expression in first if statement evaluates to be True otherwise it will directly jump on elif statement or else statement as per given code by user.

Syntax: if expression:

                  {statement/code}

                  if expression:

                      {statement/code}

                  elif expression:

                      {statement/code}

                  else:

                      {statement/code}

             elif expression:

                  {statement/code}

             else:

                  {statement/code}

Let’s check the program on decision making statements in Python to get more clear vision about the various statements used differently.

Click on statements.py

Let’s wrap up here for today. Tomorrow, we’ll study about loops which are used in Python to execute the code faster and easier. So, hold on to this today and practice well guys. I’ll be back soon. Have a great day!

FLOW CONTROL

Hello Pythonians! I’m back with another important part of Python which is FLOW CONTROL.

Till now, we have seen that program run or compiles in a sequential manner. That means, program run or compiles line by line then what if we want to break that manner to acquire our own advantage? That is why we use Flow Control in Python.

Flow Control is basically alternating the sequence of the flow or code. It is done either using Loops or Conditional/decision-making statements.

1. Conditional Statements: Conditional statements are also called Decision-Making Statements. It means that if the condition is satisfied than user can execute set of statements.

There are four types of conditional statements in Python. They are:

A) if statement

B) if…else statement

C) if…elif…else statement

D) nested if statements

2. Loops: Loops are used in program when any complex program is tended to make easier. Loops are generally used to break down the complexity and make your code smaller and efficient.

There are three types of loops in Python. They are:

A) for loop

B) while loop

C) nested loops

So, this is the general introduction of Flow Control in Python. In next post, we’ll study flow control in deep. Let’s keep it up to here today. Practice well and be a proud Pythonian. See you all soon! Have a great one!

IDENTIFIERS

IDENTIFIERS

WHAT ARE IDENTIFIERS?

Identifiers are name given to the entities like class, functions, variables, etc. It helps us to differentiate one entity from the other.

RULES FOR WRITING IDENTIFIERS:

1. Identifiers can be combination of letters in lowercase(a-z), or uppercase(A-Z), or an underscore(_), or digits(0-9). Names like python_class, pyThon, char_4, etc. are valid examples.

2. Identifiers can’t start with a digit. But it can end with a digit.

3. Keywords in python can’t be used as identifiers.

4. We can’t use or include special symbols such as !, @, #, $, %, ^, etc. in our identifier.

5. An identifier can be of any length.

RESERVED KEYWORDS

Hi people!I hope that your coding is going well with passing days. Do you know that python has it’s own reserved words or keywords? If no, then let’s learn about keywords.

WHAT ARE RESERVED KEYWORDS?

Keywords are used to define syntax and the structure of Python language. Keywords are Case-Sensitive.

NOTE:–Apart from True, False and None; all the keywords are in lower case.

I have hereby represented the table of all the keywords below:

Falsecontinuedefnotor
awaitclassdelnonlocalreturn
elsebreakeliflambdaraise
importasyncexceptiswhile
passasfinallyintry
Noneassertforifwith
Trueandfromglobalyield

So, these above are keywords in python which are used differently with the programs and plays an important role to make python code more efficient and easy. Thank you! Have a great one.

OPERATOR PRECEDENCE (DETAIL)

Hello people! I’m back with a new information on Operators.

In this post, I’m going to represent the overall precedence of all the operators from Highest to Lowest. And it starts from Left to Right.

Sr. No.Operators
1**
2~ + –
3*/ % //
4+ –
5>> <<
6&
7^ |
8<= < > >=
9< > == !=
10= %= /= //= -= += *= **=
11is isnot
12in notin
13not or and

So, we’re keeping this up to here. In next post, we’ll discuss another important topic of Basic Python. I hope this material is bringing out your talent to code on the right path. Have a great day!