Ap4b M1
Ap4b M1
DeepLearning.AI makes these slides available for educational purposes. You may not use or distribute
these slides for commercial purposes. You may make copies of these slides and use or distribute them for
educational purposes as long as you cite DeepLearning.AI as the source of the slides.
Andrew Ng
Acknowledgments
Course Introduction
AI Python for Beginners
Lesson 1: What is
Computer Programming?
Programming helps the advancement of humanity
Programming helps the advancement of humanity
Programming: command machines to do your bidding!
A set of instructions to perform a task
1.
num1 = 37
Crack an egg into a small bowl making num2 = 5
sure there are no shells on it. Set aside.
2. Add butter, or other fat, to a non-stick pan # Calculate the sum
on medium-high heat for a minute. sum = num1 + num2
3. Add egg into pan. Cook for three to four minutes. # Display the result
4. Serve. Add salt and pepper to your taste. print(sum)
Programming gives you an edge
• Automate repetitive tasks
• Analyze lots of data
• Build, improve and use AI models
Programming will let you unleash the true power of current AI tools
Why Python?
Programming Language Ratings in June 2024
Python
C++
C
Java
C#
Javascript
Go
SQL Python is currently the most popular
Visual Basic programming language.
Fortran
Delphi/Object Pascal
Swift
Assembly language • Supportive community.
MATLAB
PHP
• Chatbots like ChatGPT are reliable
Scratch
Rust
Ruby
Kotlin
COBOL
Others
Ratings (%)
Python is everywhere in AI
3 3 3 4 8 9
3 3 3 3 9 8
Images
2 2 4 2 8 9
1 0 1 0 7 5
2 2 3 3 1 1
1 1 2 2 1 1
Signal
Sound 1 4 3 31 15 6
Time
Text in Python: Strings
"Hello, World!"
Strings
• "Hello, world"
• "¯\_(ツ)_/¯"
• "2.99"
Multiline strings in Python
"""Hello, World!
It’s great to be here!"""
Triple quotes
Checking data type in python
print("Hello, World!")
Hello, World
type("Hello, World!")
str
print(2 + 6) Addition
Celsius to Farenheit:
Then multiply!
Do this first!
print(75 - 32 * 5 / 9)
Then subtract Python will do
result from 75 this step first!
print((75 – 32) * 5 / 9)
Wrap subtraction
in parentheses
AI Python for
Beginners
Lesson 7: Combining
Text and Calculations
Progress so far
Strings represent text
• "Hello, world"
• print("Hello, World!")
• print(100)
• print(3 * 4.5)
How do print statements work?
Lesson 8: Variables
Variables – what are they
age = 28
28 Value
Variable
name
Variables – what are they
age = 28
age = 5
28
Same
variable
name
Variables – what are they
age = 28
age = 5
5 New
value
Same
variable
name
age = 28 28
name = "Otto"
"Otto"
Score
450
print(f"""Otto's age in dog years is {dog_age}.
So a dog that's about {dog_age} would
be the same age as Otto. Any dog born about
{dog_age} years ago would be in the
same stage of life as Otto.""")
3.0
print(f"""Otto's age in dog years is {dog_age}.
3.0
So a dog that's about {dog_age}
3.0 would
be the same age as Otto. Any dog born about
{dog_age}
3.0 years ago would be in the
same stage of life as Otto.""")
3.0
print(f"""Otto's age in dog years is {dog_age}.
3.0
So a dog that's about {dog_age}
3.0 would
be the same age as Otto. Any dog born about
{dog_age}
3.0 years ago would be in the
same stage of life as Otto.""")
len("Hello World!")
round(42.17)
print("Hello World!")
Function data, actions and
results
This function gets the number of
characters for the string you provide
Function Data or
name arguments
len("Hello World!")
Parentheses
len("Hello World!")
12
result
Name of function
Argument
print("Hello World!")
Hello World!
Display-only result
Assigning function results to
variables
You can save function results, which is useful for
functions that return values
Variable name
string_length = 12
12
print(string_length)
12