Lecture 4 (DS) - Python Basics 2
Lecture 4 (DS) - Python Basics 2
Python - Basics
• Python
• Created by Guido van Rossum
Data Science • First released in 1991
Lecture # 4 • Widely used high-level programming language for general purpose
programming
• Python is powerful… and fast; plays well with others; runs everywhere; is
friendly & easy to learn; is open
• Will use NumPy and Pandas libraries in future, valeable for doing data
science in Python
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
• Python is dynamic
typed language there
are no explicit types for
x and y
• C, C++ are strongly
typed languages
• There are still types
behind the scene with
Python
5 6
1
10/26/17
7 8
• Objects
• By the end of this lecture, you will should be able to • Can hold data
• Can have actions associated with them
• Describe an object from a programming perspective
• Recognize that everything in python is an object • In previous slide we’ve seen that x can hold integer as well as float values
because everything in Python is an object
9 10
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
• X = 3 will create
PyIntObject with value of • First a PyFloatObject is
three created
• X is created in stack • Then x point to it
• PyIntObject in heap • Garbage collector in
• Stack holds local variable Python automatically
managed by program free the space for
PyIntObject
• Heap holds dynamic data
managed by OS 11 12
2
10/26/17
13 14
An Example An Example
15 16
17 18
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
3
10/26/17
19 20
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
21 22
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
4
10/26/17
25 26
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
• Output will be
• 2.7
• None
• Because function
is not returning
anything
27 28
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
29 30
Note: A ll Images are taken from edx.org Note: A ll Images are taken from edx.org
5
10/26/17
31