Download presentation
Presentation is loading. Please wait.
1
Pamela Moore & Zenia Bahorski
Python 1 SIGCS Intro to Python March 16, 2011 Presented by Pamela Moore & Zenia Bahorski
2
Scripting Languages Useful for system administration Web programming
text processing, etc.
3
Scripting Languages Casual with regard to the typing of variables
Variables can be different types depending on the different information stored in them. Different types were especially important when memory constraints were a bigger issue than they are today. Integers take less memory to store than real numbers which take less memory than arrays.
4
Scripting Languages Arrays (which we haven’t defined yet) can use elements of different types - unheard of in most procedural languages E.g.: Hello 68 widgets $333.99
5
Scripting Languages Lots of built in high-level operations
String concatenation (making one large string by "fusing" two smaller strings) Pushing an item onto a stack Popping an item off of a stack
6
Scripting Languages Interpreted, rather than compiled
An interpreted language is executed "on the fly", one statement at a time Can be faster Often uses less memory Easier for using on machines with different operating systems
7
Scripting Languages Interpreted, rather than compiled
A compiled language is first translated into the machine language of the host machine and then executed. Limited by the host machine in use Uses more memory since it has to hold the entire program before it is executed
8
Why Python? Python & the Python-like Ruby have momentum in the scripting world. Cleaner More elegant Popular with developers – (Google uses Python) Easier to learn
9
Why Python? Pythonista - a Python aficionado
Pythonistas advocate the use of Python for all programming, not just scripting
10
Interactive Mode Interactive mode - executing Python statements immediately Useful for quick checks of commands % python >>> prompt for a command … prompt when in a block … <return> to finish Stop and have them do some!
11
Case sensitive! Python is case sensitive
Upper and lower case letters are perceived as different things Be careful of variables - especially if you use a text processing program that automatically capitalizes sentences Ex: num & Num Ex: print & Print
12
Formatting Notes Python is picky about some characters
Indenting must be with spaces, not tabs Quotes must be non-smart double quotes (even though some versions say single or double quotes) Ex: "Hello" Ex: “Hello” or ‘Hello’ will each generate a syntax error
13
Definitions Block indicated by a : at the end of the line.
Everything after MUST be indented the same amount. Be consistent. Sub-blocks (blocks within blocks) are possible very useful.
14
Definitions List A sequence of objects (can be different things) separated by commas and enclosed in square brackets. Ex: [1, 2, 4, num] Ex: ["hello", "goodbye"] Ex: [23.5, $16.42, [0, -3], "string"]
15
Definitions Variable Letter or series of letters used to hold a value
Use descriptive variable names whenever possible Makes debugging SO much easier! Use single letter variables for loop control only! (my rule – not a Python rule)
16
Definitions Functions Call to a pre-defined mini program
Usually returns a value Call with Funcname(args) Ex: range(2) returns the list [0,1] Ex: type(3) returns <type ‘int’>
17
Definitions Counting In Python, counting starts at 0
Becomes important for some functions (like range)
18
Definitions Long lines Continue on next line with a back slash Ex:
print "This is a very very very very very long"\ "line of text continued on the next line"
19
Order of Operations Mathematical calculations are executed in the following order: Expressions within ( ) Function calls Exponentiation - raise to a power - ** Multiply & divide * & / Add & subtract + & -
20
Order of Operations Ex: x= 3 print x**3 + 5 - 6.3*2
print 12 - (max[x, 6] /3)
21
Comments To put comments in a Python program just put # as the first char Rest of the line is ignored Ex: # ignore this line of code # print the results 10 times Comments will be necessary in ALL programs! (my rule)
22
For loop preview For loop - loop will execute a definite amount of times Ex: for i in [1, 2, 3, 4]: print "i=", i Ex: for x in range(9): print "loop"
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.