SlideShare a Scribd company logo
1 of 62
Download to read offline
Hello Python
?‫מנחשים‬ ‫מפחד‬ ‫מי‬ :‫או‬
CC BY-SA 3.0 Dimid
?‫היום‬ ‫נדבר‬ ‫מה‬ ‫על‬
*‫פייתון‬ ‫למה‬
*‫תכנות‬
*‫דוגמאות‬
‫ותנאים‬ ‫שכר‬
‫אינטלקטואלי‬ ‫אתגר‬
‫מהפכנית‬ ‫טכנולוגיה‬
‫לחו״ל‬ ‫נסיעות‬
‫מגולח‬ ‫ולא‬ ‫בטישרט‬ ‫לבוא‬
‫בהייטק‬ ‫לעבוד‬ ‫סיבות‬
?‫פייתון‬ ‫למה‬
‫נקי‬ ‫סינטקס‬
class Main {
public static final String[] NAMES =
{"Yuval", "Keren", "Dvir"};
public static void main(String[] argv) {
for (String s: NAMES) {
System.out.println("Hello " + s);
}
}
}
for s in ["Yuval", "Keren", "Dvir"]:
print("Hello " + s)
‫דינמיים‬ ‫טיפוסים‬
s = "Hello Python"
String s = "Hello Python";
‫עשירה‬ ‫ספריה‬
‫נאים‬ ‫כלים‬
virtualenv
pyflakes
pip
?‫בפייתון‬ ‫נכתב‬ ‫מה‬
web
data science
Natural Language Toolkit
IOT
?‫תכנות‬ ‫זה‬ ‫מה‬
?‫תכנות‬ ‫זה‬ ‫מה‬
‫טבעונית‬ ‫גבינה‬ ‫עוגת‬ :‫מתכון‬
‫עד‬ ‫הלימון‬ ‫וגרידת‬ ‫הקוקוס‬ ‫או‬ ‫הסויה‬ ‫חלב‬ ‫עם‬ ‫הביסקוויטים‬ ‫פירורי‬ ‫את‬ ‫לערבב‬
‫או‬ ‫נוזלים‬ ‫יותר‬ ‫מעט‬ ‫להוסיף‬ ‫ניתן‬ ,‫הצורך‬ ‫במידת‬ .‫בצק‬ ‫דמוית‬ ‫עיסה‬ ‫לקבלת‬
.‫הרצוי‬ ‫המרקם‬ ‫לקבלת‬ ‫פירורים‬
.‫מעט‬ ‫ששומנה‬ ‫תבנית‬ ‫על‬ ‫התערובת‬ ‫את‬ ‫לשטח‬
.‫אחידה‬ ‫עיסה‬ ‫לקבלת‬ ‫עד‬ ‫במיקסר‬ ‫המלית‬ ‫חומרי‬ ‫את‬ ‫לערבב‬
.‫הביסקוויטים‬ ‫מעל‬ ‫העיסה‬ ‫את‬ ‫לצקת‬
.‫שעות‬ ‫למספר‬ ‫במקרר‬ ‫לצנן‬
?‫תכנות‬ ‫זה‬ ‫מה‬
‫הוא‬ ‫אם‬ ‫לבדוק‬ ‫רוצים‬ ‫ואנו‬ ,‫שלם‬ ‫חיובי‬ ‫מספר‬ ,N ‫נתון‬
‫ראשוני‬
:‫אלגוריתם‬
.12 -‫ל‬ i ‫את‬ ‫אתחל‬
.2:N -‫מ‬ ‫קטן‬ i ‫עוד‬ ‫כל‬

:‫שארית‬ ‫ללא‬ i -‫ב‬ ‫מתחלק‬ N ‫אם‬ 2.1
‫׳שקר׳‬ ‫החזר‬ 2.1.1
:‫אחרת‬
1 -‫ב‬ i ‫את‬ ‫קדם‬ 2.1.2
‫׳אמת׳‬ ‫החזר‬ .3
?‫תכנות‬ ‫זה‬ ‫מה‬
‫הוא‬ ‫אם‬ ‫לבדוק‬ ‫רוצים‬ ‫ואנו‬ ,‫שלם‬ ‫חיובי‬ ‫מספר‬ ,N ‫נתון‬
9 :‫ראשוני‬
‫צעד‬i‫שארית‬‫פעולה‬
1211 -‫ב‬ i ‫את‬ ‫קדם‬
230‫׳שקר׳‬ ‫החזר‬
?‫תכנות‬ ‫זה‬ ‫מה‬
‫הוא‬ ‫אם‬ ‫לבדוק‬ ‫רוצים‬ ‫ואנו‬ ,‫שלם‬ ‫חיובי‬ ‫מספר‬ ,N ‫נתון‬
11 :‫ראשוני‬
‫צעד‬i‫שארית‬‫פעולה‬
1211 -‫ב‬ i ‫את‬ ‫קדם‬
2321 -‫ב‬ i ‫את‬ ‫קדם‬
3431 -‫ב‬ i ‫את‬ ‫קדם‬
4521 -‫ב‬ i ‫את‬ ‫קדם‬
5651 -‫ב‬ i ‫את‬ ‫קדם‬
6741 -‫ב‬ i ‫את‬ ‫קדם‬
7831 -‫ב‬ i ‫את‬ ‫קדם‬
8921 -‫ב‬ i ‫את‬ ‫קדם‬
91011 -‫ב‬ i ‫את‬ ‫קדם‬
1011‫׳אמת׳‬ ‫החזר‬
?‫תכנות‬ ‫זה‬ ‫מה‬import sys
def is_prime(n):
i = 2
while i < n:
if n % i == 0:
return False
else:
i = i + 1
return True
if __name__ == "__main__":
n = int(sys.argv[1])
print(is_prime(n))
?‫תכנות‬ ‫זה‬ ‫מה‬
import sys


# more pythonic
def is_prime(n):
for i in range(2, n):
if n % i == 0:
return False
return True
if __name__ == "__main__":
n = int(sys.argv[1])
print(is_prime(n))
‫חידה‬
‫חידה‬
‫מדרגות‬‫דרכים‬
11
22
33
4?
5?
‫חידה‬
1, 1, 2, 3, 5, 8, …
‫פיבונצ׳י‬
import sys
def fib(n):
if n <= 2:
return 1
return fib(n - 2) + fib(n - 1)
if __name__ == "__main__":
n = int(sys.argv[1])
print(fib(n))
?‫יהודי‬ ‫מיהו‬
‫פיבונצ׳י‬import sys


# assume n >= 3
def fib(n):
sum_i = 0
i = 3
f2, f1 = 1, 1
while i <= n:
sum_i = f2 + f1
f2, f1 = f1, sum_i
i += 1
return sum_i
if __name__ == "__main__":
n = int(sys.argv[1])
print(fib(n))
‫פיבונצ׳י‬
f2, f1 = f1, f1 + f2
f2 = f1

f1 = f1 + f2
?
‫פיבונצ׳י‬
import sys
# more pythonic
def fib(n):
f2, f1 = 1, 1
for i in range(3, n + 1):
f2, f1 = f1, f1 + f2
return f1
if __name__ == "__main__":
n = int(sys.argv[1])
print(fib(n))
‫פיבונצ׳י‬
In [83]: %time %run fib 39
63245986
CPU times: user 15.5 s, sys: 63.1 ms,
total: 15.6 s

Wall time: 15.7 s
O(2ⁿ)
In [84]: %time %run fib2 39
63245986
CPU times: user 1.01 ms, sys: 664 µs,
total: 1.67 ms

Wall time: 1.14 ms
O(n)
‫פיבונצ׳י‬import sys
known = {
1: 1,
2: 1,
}
def fib(n):
if n in known:
return known[n]
known[n] = fib(n - 2) + fib(n - 1)
return known[n]
if __name__ == "__main__":
n = int(sys.argv[1])
print(fib(n))
‫פיבונצ׳י‬
import sys
from functools import lru_cache
# more pythonic
@lru_cache(maxsize=None)
def fib(n):
if n <= 2:
return 1
return fib(n - 2) + fib(n - 1)
if __name__ == "__main__":
n = int(sys.argv[1])
print(fib(n))
big O
http://bigocheatsheet.com/
‫רקורסיה‬
import sys
def power(x, n):
res = 1
while n > 0:
res *= x
n -= 1
return res
if __name__ == "__main__":
x = int(sys.argv[1])
n = int(sys.argv[2])
print(power(x, n))
‫רקורסיה‬
import sys
# assume n is a power of 2
def power(x, n):
if n == 2:
return x * x
return power(x, n / 2) * power(x, n / 2)
if __name__ == "__main__":
x = int(sys.argv[1])
n = int(sys.argv[2])
print(power(x, n))
‫רקורסיה‬import sys
def power(x, n):
if n == 1:
return x
elif n % 2 == 0:
half = power(x, n / 2)
return half * half
else:
return x * power(x, n - 1)
if __name__ == "__main__":
x = int(sys.argv[1])
n = int(sys.argv[2])
print(power(x, n))
‫רקורסיה‬
%time %run power2 2 65536

[…]

CPU times: user 110 ms, sys: 8.22 ms,
total: 118 ms
Wall time: 116 ms
%time %run power3 2 65536

[…]

CPU times: user 8.6 ms, sys: 1.37 ms,
total: 9.97 ms
Wall time: 12.7 ms
?‫עובד‬ ‫זה‬ ‫איך‬
print(“hello”)
01010101
1100011
hello
language ≠
Implementation
‫חישוב‬ ‫כח‬
‫משתנים‬
What’s in a name? that which we call a rose

By any other name would smell as sweet

‫ה‬‫שושנ‬ ‫לו‬ ‫שנקרא‬ ‫מה‬ ?‫בשם‬ ‫יש‬ ‫מה‬
‫אחר‬ ‫שם‬ ‫כל‬ ‫תחת‬ ‫מתוק‬ ‫יהיה‬ ‫ריחו‬
‫משתנים‬
cow_sound = "moo"
animals = ["antelope", "bat", "cat", "dog", "eagle"]
animal_to_voice = {
"antelope": "snort",
"bat": "spreech",
"cat": "meow",
"dog": "woof",
}
def make_sound(animal):
sound = animal_to_voice.get(animal, cow_sound)
print(sound)
‫משתנים‬
st = "moo"
lst = ["antelope", "bat", "cat", "dog", "eagle"]
a2v = {
"antelope": "snort",
"bat": "screech",
"cat": "meow",
"dog": "woof",
}
def sound(animal):
…
‫קובע‬ ‫כן‬ ‫הגודל‬
A ≠ a
‫משתנים‬ ‫סוגי‬
<x, y, z>
‫משתנים‬ ‫סוגי‬
a = b = 5
a = 1
b
a = b = [5]

a = [1]
b
‫משתנים‬ ‫סוגי‬
a = b = 5
a = 1
b
a = b = (5)

a = (1)
b
‫משתנים‬ ‫סוגי‬
a = b = 5
a = 1
b
a = b = “hi”

a = “there”
b
‫משתנים‬ ‫סוגי‬
a = “hi”

id(a)

a += “there”
id(a)
a = [“hi”]

id(a)

a += [“there”]
id(a)
‫תרגול‬
$vim hello.py

$python hello.py

hello python
‫תרגול‬
import sys
def concat(n):
res = ''
for i in range(0, n):
res += str(i)
return res
if __name__ == '__main__':
concat(int(sys.argv[1]))
‫תרגול‬
import sys
def concat(n):
res = []
for i in range(0, n):
res += str(i)
return(''.join(res))
if __name__ == '__main__':
concat(int(sys.argv[1]))
‫תרגול‬
import sys
def concat(n):
res = []
for i in range(0, n):
res.append(str(i))
return(''.join(res))
if __name__ == '__main__':
concat(int(sys.argv[1]))
‫תרגול‬
import sys
def concat(n):
res = [str(i) for i in range(0, n)]
return(''.join(res))
if __name__ == '__main__':
concat(int(sys.argv[1]))
?‫כשנתקעים‬ ‫קורה‬ ‫מה‬
comp.lang.python
docs.python.org/3/
?‫כשנתקעים‬ ‫קורה‬ ‫מה‬
simple web-server
AMA
?‫הלאה‬ ‫מה‬
0-100
Credits
CC ‫סדן‬ ‫מאיר‬ - ‫שוקו‬‫פונט‬
‫ת״א‬ ‫אוני׳‬ ‫של‬ ‫הקורס‬ ‫על‬ ‫בחלקו‬ ‫מבוסס‬
(‫שייקספיר‬ ,‫דייקסטרה‬ ‫)ציטוט‬
The Hitchhiker’s Guide to Python!
Credits :‫תמונות‬
Wikipedia
Credits
:‫תמונות‬
xkcd ‫הישראלי‬ ‫והטבעונות‬ ‫הצמחונות‬ ‫אתר‬
Remirat
pixabay

More Related Content

Featured

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Featured (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Hellopy