A loop is a construct that controls the repeated execution of a block statements.
While Loop - A while loop executes statements repeatedly as long as a condition remains true.
The while loop is a condition-controlled loop; it is controlled by a true/false condition.
The for loop is a count-controlled loop that repeats a specified number of times.
For Loop - A python for loop iterates through each value in a sequence.
Nested Loops A loop can be nested inside another loop.
Nested loops consist of an outer loop and one or more inner loops.
Each time the outer loop is repeated, the inner loops are started a new.
A FUNCTION is a block of code which only runs when it is called.
A function is a block of code which only runs when it is called.
Functions can be used to define reusable code and organize and simplify code.
You can pass data, known as parameters, into a function.
Defining a Function - A function definition consists of the function’s name, parameters, and body.
The variables in the function header are known as formal parameters or simply parameters. A parameter is like a placeholder.
If a function returns a value, it is called a value-returning function.
Calling a Function Calling a function executes the code in the function.
Functions with/without Return values.A function does not have to return a value.
The program defines a function named printGrade and invokes it to print the grade for a given score.
The printGrade function does not return any value, and it must be invoked as a statement.
We call the new function that returns the grade, getGrade.
The getGrade function returns a character, and it can be invoked and used just like a character.
Defining Classes for Objects A class defines the properties and behaviors for objects.
Object-oriented programming (OOP) involves the use of objects to create programs.
When working with objects, variables are called attributes and functions are called methods.
Python uses methods to define an object’s behavior (also known as its actions.)
Python ClassesA class is considered a blueprint of objects.
Python ObjectsAn object is called an instance of a class. The syntax to create an object.
Access Class Attributes Using Objects- We use the . notation to access the attributes of a class.
You can access the object’s data fields and invoke its methods by using the dot operator (.), also known as the object member access operator.
Python Methods - we can also define a function inside a Python class.
An initializer can perform any action, but initializers are designed to perform initializing actions, such as creating an object’s data fields with initial values.
Constructing Objects all methods, including the initializer, have the first parameter self.
Python Constructors - __init__() is the constructor function that is called whenever a new object of that class is instantiated.
__init__() This method, is known as an initializer.
The self-parameter in the __init__ method is automatically set to reference the object that was just created.
The first parameter for each method defined is self.
The self-Parameter - self is a parameter that references the object itself.
Using self, you can access object’s members in a class definition.
A Python function defined inside a class is called a method.