Upload
ambrose-stewart
View
229
Download
0
Tags:
Embed Size (px)
Citation preview
4
Installing and Running Python 2.7
• Python 2.7 is already installed in the computers’ classroom
• Install:• Windows 32 bit: http://www.python.org/ftp/python/2.7.2/python-2.7.2.msi
• A “Python 2.7” folder will be created in your Start Menu:• IDLE (Python GUI) - recommended working environment
• Python (command line) - textual Python interpreter (a little faster, less convenient)
• Working with IDLE video: http://www.youtube.com/watch?v=lBkcDFRA958
14
Machine Code (Language)
• Computers understand only machine language• Basically looks like a sequence of 1’s and 0’s• Very inconvenient to work with and non intuitive
• All other computer languages were created for human convenience• The computer does not understand C/C#/Java/Scala• Must be “translated” into machine language
15
Programming Languages Basics
• A computer program is a sequence of instructions (texts) that can be “understood" by a computer and executed by it
• A programming language is a machine-readable artificial language designed to express computations that can be performed by a computer
19
Interpreter
• Python is an interpreted programming language
• The Read/Evaluate/Print Loop• Read an expression
• Compute its value• Print the result• Repeat the above
20
Language Selection and Python
• Goal• Runtime vs. Development time• Operating systems• Platforms
•Python is appropriate for quick development of small-medium tasks:
• Experiments• Data analysis• Small projects• Short development-execution rounds
22
Memory (Cont.)
• The computer memory is composed of a long list of bits
• Bits are grouped into bytes and words
• Every byte is numbered sequentially
• This number is called an address
23
Variables and Types
): יחידת מידע המאכסנת ערך variable (משתנה•במהלך ריצת התכנית
ניתן ל"גשת" למשתנה: לשנות (לא תמיד) או לקבל את •ערכו
ניתן לבצע פעולות חשבוניות (ואחרות) בעזרת משתנים•שקובע את אופן ביצוע )type (טיפוסלכל משתנה מוגדר •
הפעולות על המשתנה
24
Define Variables
variable name
valueassignment operator
Variable x “is of type” Int and is assigned the value 4
25
Why do We Need Variables?
• Computer programs manipulate data• Data is given as input or calculated throughout
the program• To be later accessed, variables must be
remembered• Thus, variables are stored in the memory• Variable name memory address
26
Types
• Determine number of bytes in memory (“locker size”)
• Determine the operations that are defined for a given variable
29
Why Do We Need Different Types?
• Saving memory
• Execution speed
• Defined operations
• Makes compiler “life” easier (not relevant in Python)