اليوم 3 — أساسيات Python
Day 3: Python Basics
Welcome to Day 3 of your 100-day AI learning journey! Today, we will start learning Python, a powerful and versatile programming language widely used in AI and data science.
Objectives:
- Understand Python syntax.
- Learn basic programming concepts in Python.
- Follow along with the "Python for Beginners" course.
Topics to Explore:
1. Python Syntax
Python syntax is designed to be readable and straightforward. Key elements include:
- Variables: Used to store data values.
CODE EXAMPLE
x = 5 y = "Hello, World!"
Data Types
Common types include integers, floats, strings, and booleans.
age = 25 # int
price = 19.99 # float
name = "Alice" # str
is_student = True # bool
Comments
Used to explain code, ignored by the interpreter.
# This is a comment
Indentation
Python uses indentation to define blocks of code.
if age > 18:
print("You are an adult.")
-
Control Flow:
-
If-else statements: Used to make decisions in your code.
CODE EXAMPLEif age > 18: print("You are an adult.") else: print("You are a minor.") -
For loops: Used to iterate over a sequence (like a list, tuple, or string).
CODE EXAMPLEfor i in range(5): print(i) -
While loops: Repeats as long as a condition is true.
CODE EXAMPLEcount = 0 while count < 5: print(count) count += 1
-
-
Functions:
-
Defining a function: A reusable block of code.
CODE EXAMPLEdef greet(name): print(f"Hello, {name}!") -
Calling a function:
CODE EXAMPLEgreet("Alice")
-
3. Follow Along with "Python for Beginners"
"Python for Beginners" is an excellent resource to start your Python journey. This course covers all the basics and helps you build a strong foundation in Python programming.
Course Details:
- Duration: Approximately 4-6 hours.
- Structure:
- Module 1: Introduction to Python
- Setting up your development environment.
- Writing your first Python program.
- Module 2: Basic Syntax and Data Types
- Understanding variables, data types, and basic operations.
- Module 1: Introduction to Python
Course Details:
- Module 3: Control Flow
- Writing if-else statements, loops, and understanding logical conditions.
- Module 4: Functions
- Creating and using functions to make your code modular and reusable.
Activities:
- Read: Go through the first few chapters of "Automate the Boring Stuff with Python" by Al Sweigart. This book is available for free online and is a great resource for beginners.
- Watch: Complete at least the first two modules of the "Python for Beginners" course. Follow along with the exercises and code examples.
- Practice: Write simple Python programs to reinforce what you’ve learned. Here are a few ideas:
- Print the numbers 1 to 10.
- Write a program that asks for the user's name and greets them.
- Create a function that takes two numbers and returns their sum.
Summary:
Today, you learned the basics of Python syntax and programming concepts. By following along with the "Python for Beginners" course and practicing on your own, you’re laying a strong foundation for your AI journey.
Remember to practice regularly and build small projects to solidify your understanding. Tomorrow, we'll continue with more advanced Python concepts. See you on Day 4!
Happy coding!
