Getting Started with Python Programming

Aug 7, 2024

Python Programming Tutorial Notes

Introduction

  • Learn Python for data science, machine learning, web development.
  • No prior knowledge required.
  • Instructor: Mosh Hamedani.
  • New videos released weekly on the channel.

What You Can Do with Python

  • Multi-purpose language:
    • Machine learning and AI (top choice for projects)
    • Web development (popular framework: Django)
      • Websites using Django: YouTube, Instagram, Spotify, Dropbox, Pinterest.
    • Automation: save time and increase productivity.

Installing Python

  1. Go to python.org to download the latest version.
  2. Check "Add Python to PATH" during installation on Windows.
  3. Install a code editor (recommended: PyCharm).
    • Get it from jetbrains.com.
    • Download the free Community Edition.
  4. Set up your first project in PyCharm:
    • Create a new project and add a Python file.

First Python Code

  • Write a simple program:
    print("Hello, World!")
    
  • Explanation:
    • print is a built-in function to output messages.
    • Strings should be enclosed in quotes (single or double).

Variables in Python

  • Variables are used to store data:
    • Example:
      age = 20
      
  • Print variable values:
    print(age)
    
  • Variable naming:
    • Use underscores for readability (e.g., first_name).
    • Case sensitive (e.g., True, False).

User Input

  • Use the input() function to read user input:
    name = input("What is your name? ")
    print("Hello, " + name)
    

Data Types

  • Basic types:
    • Numbers (integers & floats)
    • Strings
    • Booleans (True/False)
  • Type conversion functions:
    • int(), float(), str(), bool()

Arithmetic Operations

  • Basic operators: +, -, *, /
  • Division operators:
    • Single slash (returns float)
    • Double slash (returns integer)
    • Modulus (%) for remainder.
    • Exponentiation (**).

Comparison Operators

  • Used to compare values:
    • >, <, >=, <=, ==, !=

Logical Operators

  • Combine multiple conditions:
    • and, or, not

If Statements

  • Make decisions in code:
    if temperature > 30:
        print("It's a hot day")
    elif temperature > 20:
        print("It's a nice day")
    else:
        print("It's cold")
    

Loops

  • While Loops: Repeat code while a condition is true.
    i = 1
    while i <= 5:
        print(i)
        i += 1
    
  • For Loops: Iterate over a sequence.
    for num in range(5):
        print(num)
    

Lists

  • To store sequences:
    names = ["John", "Bob", "Alice"]
    
  • Methods: append(), insert(), remove(), clear().
  • Use in operator to check for existence.
  • Length of a list: len(list).

Tuples

  • Like lists but immutable:
    numbers = (1, 2, 3)
    
  • Methods: count(), index().

Conclusion

  • Python offers a range of functionalities, making it versatile for various applications.
  • Further learning available at codewoodmosh.com for comprehensive courses.