Embed presentation
















![Variables• Like all programming languages, Python variablesare similar to variables in Algebra.• They act as place holders or symbolicrepresentations for a value, which may or may notchange over time.• Here are six of the most important variable typesin Python:int Plain Integers ( 25 )long Long Integers ( 4294967296 )float Floating-point Numbers( 3.14159265358979 )bool Booleans ( True, False )str Strings ( “Hello World!” )list Sequenced List ( [25, 50, 75, 100])](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-17-2048.jpg&f=jpg&w=240)




![Numerical Precision• Integers• Generally 32 signed bits of precision• [2,147,483,647 .. –2,147,483,648]• or basically (-232, 232)• Example: 25• Long Integers• Unlimited precision or size• Format: <number>L• Example: 4294967296L• Floating-point• Platform dependant “double” precision• Example: 3.141592653589793](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-22-2048.jpg&f=jpg&w=240)





















![for Statement• The for statement allows us to repeat an action based on theiteration of a Sequenced List.weapons = [ “Pistol”, “Rifle”, “Grenade”, “Rocket Launcher” ]print “-- Weapon Inventory --”for x in weapons:print x• The for statement will loop once for every item in the list.• Note how we use the temporary variable ‘x’ to represent thecurrent item being worked with.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-44-2048.jpg&f=jpg&w=240)

![break Keyword• The break keyword can be used to escape from while and forloops early.numbers = [100, 25, 125, 50, 150, 75, 175]for x in numbers:print x# As soon as we find 50 - stop the search!if x == 50:print "Found It!"break;• Instead of examining every list entry in “numbers”, The forloop above will be terminated as soon as the value 50 isfound.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-46-2048.jpg&f=jpg&w=240)

![continue Keyword• The continue keyword can be used to short-circuit or bypassparts of a while or for loop.numbers = [100, 25, 125, 50, 150, 75, 175]for x in numbers:# Skip all triple digit numbersif x >= 100:continue;print x• The for loop above only wants to print double digit numbers.It will simply continue on to the next iteration of the for loopif x is found to be a triple digit number.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-48-2048.jpg&f=jpg&w=240)















![Assigning the return value• Here’s how the return value of our average function would beused…myNumbers = [5.0, 7.0, 8.0, 2.0]theAverage = average( myNumbers )print "The average of the list is " + str( theAverage ) + "."• Note how we assign the return value of average to ourvariable called “theAverage”.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-64-2048.jpg&f=jpg&w=240)


![Assigning the return values• Here’s how the multiple return value of our average functioncould be used…myNumbers = [5.0, 7.0, 8.0, 2.0]theAverage, numberCount = average( myNumbers )print "The average of the list is " + str( theAverage ) + "."print "The list contained " + str( numberCount ) + " numbers.“• Note how we assign the return values of average to ourvariables “theAverage” and “numberCount”.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-67-2048.jpg&f=jpg&w=240)



This document provides an introduction and overview of the Python programming language. It discusses what Python is, why to learn a scripting language and why Python specifically. It covers how to install Python and how to edit Python code using IDLE. The rest of the document demonstrates various Python concepts like variables, data types, operators, flow control statements, functions and more through sample code examples. Each code example is accompanied by instructions to run the sample script in IDLE.
















![Variables• Like all programming languages, Python variablesare similar to variables in Algebra.• They act as place holders or symbolicrepresentations for a value, which may or may notchange over time.• Here are six of the most important variable typesin Python:int Plain Integers ( 25 )long Long Integers ( 4294967296 )float Floating-point Numbers( 3.14159265358979 )bool Booleans ( True, False )str Strings ( “Hello World!” )list Sequenced List ( [25, 50, 75, 100])](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-17-2048.jpg&f=jpg&w=240)




![Numerical Precision• Integers• Generally 32 signed bits of precision• [2,147,483,647 .. –2,147,483,648]• or basically (-232, 232)• Example: 25• Long Integers• Unlimited precision or size• Format: <number>L• Example: 4294967296L• Floating-point• Platform dependant “double” precision• Example: 3.141592653589793](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-22-2048.jpg&f=jpg&w=240)





















![for Statement• The for statement allows us to repeat an action based on theiteration of a Sequenced List.weapons = [ “Pistol”, “Rifle”, “Grenade”, “Rocket Launcher” ]print “-- Weapon Inventory --”for x in weapons:print x• The for statement will loop once for every item in the list.• Note how we use the temporary variable ‘x’ to represent thecurrent item being worked with.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-44-2048.jpg&f=jpg&w=240)

![break Keyword• The break keyword can be used to escape from while and forloops early.numbers = [100, 25, 125, 50, 150, 75, 175]for x in numbers:print x# As soon as we find 50 - stop the search!if x == 50:print "Found It!"break;• Instead of examining every list entry in “numbers”, The forloop above will be terminated as soon as the value 50 isfound.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-46-2048.jpg&f=jpg&w=240)

![continue Keyword• The continue keyword can be used to short-circuit or bypassparts of a while or for loop.numbers = [100, 25, 125, 50, 150, 75, 175]for x in numbers:# Skip all triple digit numbersif x >= 100:continue;print x• The for loop above only wants to print double digit numbers.It will simply continue on to the next iteration of the for loopif x is found to be a triple digit number.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-48-2048.jpg&f=jpg&w=240)















![Assigning the return value• Here’s how the return value of our average function would beused…myNumbers = [5.0, 7.0, 8.0, 2.0]theAverage = average( myNumbers )print "The average of the list is " + str( theAverage ) + "."• Note how we assign the return value of average to ourvariable called “theAverage”.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-64-2048.jpg&f=jpg&w=240)


![Assigning the return values• Here’s how the multiple return value of our average functioncould be used…myNumbers = [5.0, 7.0, 8.0, 2.0]theAverage, numberCount = average( myNumbers )print "The average of the list is " + str( theAverage ) + "."print "The list contained " + str( numberCount ) + " numbers.“• Note how we assign the return values of average to ourvariables “theAverage” and “numberCount”.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpython-introduction-15584%2f75%2fPython-Introduction-67-2048.jpg&f=jpg&w=240)

