In this video, I will explain the basics of Object Oriented Programming with Python. Understand that a Class is the blue print that defines what Attributes (variables) and Methods (functions), each object it builds must have.
Each Object that is created is said to be an Instance of the Class that built it. I’ll also go over what Encapsulation is. Encapsulation is how you hide information and constrain a user of your class to use it in the way you define. And, finally I teach you how to enforce Encapsulation by making your Attributes and Methods private.
Like always, a lot of code follows the video. If you have any questions or comments leave them below. And, if you missed my other Python Tutorials they are available here:
In this video I’ll explain how to use functions in Python 2.5 through 2.7. I’m going to cover how to:
Create Functions
Pass Values to Functions
Create Default Values
Except Unlimited Arguments
Except Unlimited Key Value Pairs
Use Recursion
and more…
Like always, the code follows the video. If you have any questions or comments leave them below. And, if you missed my other Python Tutorials they are available here:
Here is Some Code that Demonstrates using Python Functions
#! /usr/bin/python
# Define a docstring a special function attribute
globalVariable = 10
def addNumbers(NumOne=1,NumTwo=1):
‘Adds the numbers passed to it’
return NumOne + NumTwo
def addUndefNums(NumOne=1,NumTwo=1,*args):
‘Adds the numbers passed to it’
finalValue = NumOne + NumTwo
if args:
for i in args:
finalValue += i
return finalValue
else:
return finalValue
def createDict(**kvargs):
for i in kvargs:
print i, kvargs[i]
print type(kvargs[i])
print type(kvargs)
print kvargs
return
def factorial(num):
if num == 1:
return 1
else:
return num * factorial(num – 1)
def printNames(first,last):
pass
def main():
# Demonstrate difference between global & local scope
mainNumber = 5
print “mainNumber equals”, mainNumber, “in function main”
scopeFunction()
print “mainNumber equals”, mainNumber, “after scopeFunction”
print id(mainNumber)
# Force a global variable to change
print “globalVariable before changeGlobal =”, globalVariable
changeGlobal()
print “globalVariable after changeGlobal =”, globalVariable
# Create a function with a docstring
print addNumbers(1)
print addNumbers.__doc__
# Add undefined number of numbers with a tuple
print addUndefNums(1,2,3,4,5,6,7,8)
# Create a dictionary
createDict(Name=’Derek’, Age=35, YearBorn=1974)
createDict(Cust1=(‘Derek’,35,1974),Cust2=(‘Sally’,25,1984),Cust3=(‘Paul’,15,1994))
In this Python Video Tutorial I focus on looping in Python 2.5 through 2.7. I explain how to use the while loop and the many ways to use the for loop.
Along the way I explain how the in operator is used in Python and the range function.
Like always, the code follows the video. If you have any questions or comments leave them below. And, if you missed my other Python Tutorials they are available here:
I continue the Python 2.7 Tutorial by explaining a couple new things. I first go over how to turn your Python code into an executable application.
I then cover Python Conditionals. Conditionals are used to perform certain actions under one condition and other actions based on other conditions. In Python you can do this either with an IF Statement, or with something called a Conditional Expression.
Like always, the code follows the video. If you have any questions or comments leave them below. And, if you missed my other Python Tutorials they are available here: