๐Ÿ

Introduction to Python Programming

Jan 27, 2025

Python Programming Tutorial by Mosh Hamadani

Introduction

  • Python is a multi-purpose programming language
  • Useful for machine learning, AI, web development, and automation
  • Popular websites like YouTube, Instagram, and Pinterest use Python
  • Mosh Hamadani teaches Python from scratch

Setting Up Python

  • Download Python from python.org
  • Install Python and ensure itโ€™s added to the system path
  • Install a code editor like PyCharm (Community Edition is free)
  • Create a Python project in PyCharm

Writing Your First Python Program

  • Use print() function to display output
  • Strings are enclosed in quotes (single or double)

Variables

  • Store data values with variables
  • Declare variables using =
  • Example: age = 20
  • Supports integers, floats, strings, and booleans
  • Python is case-sensitive

User Input and Type Conversion

  • input() function to receive input from users
  • Convert input to desired type using int(), float(), bool(), or str()
  • Handle type conversion to avoid errors

String Methods

  • Strings have methods like .upper(), .lower(), .find(), and .replace()
  • Use in operator to check for substrings

Arithmetic and Comparison Operators

  • Basic operations: +, -, *, /
  • Division: / (float), // (integer)
  • Other operations: % (modulus), ** (exponentiation)
  • Comparison: >, <, ==, !=, >=, <=***

Logical Operators

  • Logical conditions: and, or, not
  • Combine conditions in if statements

Control Flow: If Statements

  • Use if, elif, and else to make decisions
  • Indentation defines code blocks

Loops

  • While Loops: Repeat code while a condition is true
    • Example: Print numbers 1 to 5
  • For Loops: Iterate over sequences like lists, strings, or ranges

Lists

  • Create lists using square brackets, e.g., names = ['John', 'Bob']
  • Access elements using indices
  • Lists are mutable
  • Methods: append(), insert(), remove(), and clear()

Tuples

  • Similar to lists but immutable
  • Created using parentheses, e.g., numbers = (1, 2, 3)

Range Function

  • Generate sequences of numbers
  • Can specify start, stop, and step

Conclusion

  • Python is versatile for various applications
  • Practice exercises to deepen understanding
  • Further learning available at Mosh's online coding school

Additional Resources