Presentation is loading. Please wait.

Presentation is loading. Please wait.

שיעור 8:tuple, פונקציות 2, sets, dict מבוא ל Python שיעור 5: set, פונקציות, dict.

Similar presentations


Presentation on theme: "שיעור 8:tuple, פונקציות 2, sets, dict מבוא ל Python שיעור 5: set, פונקציות, dict."— Presentation transcript:

1 שיעור 8:tuple, פונקציות 2, sets, dict מבוא ל Python שיעור 5: set, פונקציות, dict

2 שיעור 8:tuple, פונקציות 2, sets, dict שיעור 5  Tuple  dict  Sets  פונקציות 2

3 שיעור 8:tuple, פונקציות 2, sets, dict

4

5

6

7

8 שיעור 5  Tuple  dict  Sets  פונקציות 2

9 שיעור 8:tuple, פונקציות 2, sets, dict Dict()  טיפוס הנתונים המילון מקביל ל-hash ב שפות תכנות אחרות כמו למשל perl, או hashtable ב-JAVA.  מילון הוא טיפוס נתונים המכיל זוגות של נתונים: מפתח וערך, ומאפשר גישה יעילה לערכים על פי מפתחותיהם.  כדי להבין כיצד עובדים מילונים בפיתון, נשים לב לקטע הקוד בשקף הבא:

10 שיעור 8:tuple, פונקציות 2, sets, dict Dict()  יצירת מילון חדש בן שני איברים, והשמתו לתוך המשתנה  יצירת מילון נעשית על ידי כתיבת הזוגות מפתח - נקודותיים - ערך ( המפתח משמאל לערך כמובן ) מופרדים בפסיקים, בתוך סוגריים מסולסלים או ע " י השימוש במילה dict.

11 שיעור 8:tuple, פונקציות 2, sets, dict Dict()  דוגמאות נוספות  http://docs.python.org/3.3/tutorial/datastructures.html#dictionaries

12 שיעור 8:tuple, פונקציות 2, sets, dict שיעור 5  dict  Sets  פונקציות 2

13 שיעור 8:tuple, פונקציות 2, sets, dict Sets Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the set() function can be used to create sets.

14 שיעור 8:tuple, פונקציות 2, sets, dict sets() fast membership testing

15 שיעור 8:tuple, פונקציות 2, sets, dict sets() Demonstrate set operations on unique letters from two words

16 שיעור 8:tuple, פונקציות 2, sets, dict שיעור 4  dict  Sets  פונקציות 2

17 שיעור 8:tuple, פונקציות 2, sets, dict פונקציות 2 (המשך)  Default Argument Values  A useful form is to specify a default value for one or more arguments.  This creates a function that can be called with fewer arguments than it is defined to allow. For example: This example also introduces the in keyword. This tests whether or not a sequence contains a certain value. Usages:

18 שיעור 8:tuple, פונקציות 2, sets, dict פונקציות 2 (המשך)  Keyword Arguments¶  Functions can also be called using keyword arguments of the form kwarg=value. For instance, the following function:  accepts one required argument (voltage) and three optional arguments (state, action, and type). This function can be called in any of the following ways:  : parrot(1000) # 1 positional argument parrot(voltage=1000) # 1 keyword argument parrot(voltage=1000000, action='VOOOOOM') # 2 keyword arguments parrot(action='VOOOOOM', voltage=1000000) # 2 keyword arguments parrot('a million', 'bereft of life', 'jump') # 3 positional arguments parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 keyword

19 שיעור 8:tuple, פונקציות 2, sets, dict פונקציות 2 (המשך)  Default Argument Values  Important warning : The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. For example, the following function accumulates the arguments passed to it on subsequent calls:

20 שיעור 8:tuple, פונקציות 2, sets, dict פונקציות 2 (המשך)  **name receives a dictionary containing all keyword arguments except for those corresponding to a formal parameter.  *name receives a tuple containing the positional arguments beyond the formal parameter list.  *name must occur before **name.  For example, if we define a function like this:example, if we define a function like this:

21 שיעור 8:tuple, פונקציות 2, sets, dict פונקציות 2 (המשך)


Download ppt "שיעור 8:tuple, פונקציות 2, sets, dict מבוא ל Python שיעור 5: set, פונקציות, dict."

Similar presentations


Ads by Google