In this JavaScript video tutorial I spend some time explaining the complexity of using Arrays and Functions in JavaScript. If you missed part 1, watch that first JavaScript Video Tutorial.
JavaScript Arrays are different from many languages because you can pretty much throw anything in them. This is because JavaScript isn’t strongly typed once again.
JavaScript Functions are also odd because they don’t follow the normal scoping rules used in most other languages. And, did you know you can completely disregard the number of arguments a function will accept? You’ll learn this plus how to:
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))