Download presentation
Presentation is loading. Please wait.
Published byAmbrose Stewart Modified over 9 years ago
1
1 Programming for Engineers in Python Autumn 2011-12 Lecture 2: More Basics
2
2 Lecture 1: Highlights Functions Control structures (if/else) Strings
3
3 Today Leftovers from last week Compiler, interpreter Variables, types, operators, scope
4
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 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 http://www.youtube.com/watch?v=lBkcDFRA958
5
5 String Type http://docs.python.org/tutorial/introduction.html#strings
6
6 Strings Structure
7
7 Slicing olleH 43210 -2-3-4-5
8
8 Lists
9
9 Iterating Over Lists for var in list: print(var) value in list while loop in tirgul
10
10 Lists Built In Methods
11
11 Range, Sum
12
12 Abstruse Goose, Computer Programming 101,Computer Programming 101
13
13 Abstruse Goose, Under The HoodUnder The Hood
14
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
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
16
16 Compiler
17
17 Hello World (in C) ;-)
18
18 Interpreter
19
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
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
21
21 Memory
22
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
23 Variables and Types משתנה (variable): יחידת מידע המאכסנת ערך במהלך ריצת התכנית ניתן ל"גשת" למשתנה: לשנות (לא תמיד) או לקבל את ערכו ניתן לבצע פעולות חשבוניות (ואחרות) בעזרת משתנים לכל משתנה מוגדר טיפוס (type) שקובע את אופן ביצוע הפעולות על המשתנה
24
24 Define Variables variable name value assignment operator Variable x “is of type” Int and is assigned the value 4
25
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
26 Types Determine number of bytes in memory (“locker size”) Determine the operations that are defined for a given variable
27
27 Some Basic Types
28
28 Variables and Types
29
29 Why Do We Need Different Types? Saving memory Execution speed Defined operations Makes compiler “life” easier (not relevant in Python)
30
30 Arithmetic Operators
31
31 Example 1
32
32 Types and Casting
33
33 Example 3
34
34 Comparisons
35
35 Example 1
36
36 Example 2
37
37 Logical Operators 01 0 00 1 01 01 0 01 1 11 01 10 and or not Truth Tables (1 – True, 0 - False)
38
38 Scope
39
Next Week – A Big Jump! A cape will not help – work hard!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.