🐍

Python Tutorial Overview - Key Points by Mosh Hamedani

Jun 27, 2024

Python Tutorial by Mosh Hamedani

Introduction

  • Target audience: Beginners with no prior coding experience
  • Applications of Python:
    • Data Science
    • Machine Learning
    • Web Development
    • Automation
  • Flexible use cases demonstrated by popular sites like YouTube, Instagram, etc.

Setup

  1. Download Python: Go to python.org and download the latest version
  2. Install Python: Complete the installation, making sure to add Python to PATH on Windows
  3. Install Code Editor: Recommended editor: PyCharm
    • Download from jetbrains.com
    • Use the free Community Edition
    • Install and configure PyCharm
  4. Create a New Project: Name your project and create a new Python file
  5. Write and Run Code: Example - print("Hello World")
  6. Using Terminal: Viewing the output in the terminal window

Basics of Python

Variables

  • Declaration: Example age = 20
  • Printing Variables: print(age)
  • Types of Data:
    • Numbers: Integers and floats
    • Strings: Textual data surrounded by quotes
    • Booleans: True or False
  • Examples: price = 19.95, first_name = "John"
  • Modification: Variables can be reassigned new values

Input from User

  • input Function: Reading input from terminal
  • Example: name = input("What is your name?") print("Hello " + name)
  • Type Conversions:
    • int(x), float(x), bool(x), str(x)
  • Calculator Example: Addition of two numbers

Working with Strings

  • String Methods:
    • .upper(), .lower(), .find(), .replace()
  • String Operations: Combining and manipulating text sequences
  • Use of in Operator: Check for substrings
  • Example: course = "Python for Beginners" print(course.upper())

Arithmetic Operations

  • Basic Operators: +, -, *, /
  • Special Division Operators: single vs double slashes
  • Modulus: % (Remainder)
  • Exponent: **
  • Examples: 10 + 3 10 // 3 10 ** 3
  • Operator Precedence: Parentheses to change order

Comparison and Logical Operators

  • Comparison Operators: >, <, >=, <=, ==, !=
  • Logical Operators: and, or, not
  • Example: price = 25 print(price > 10 and price < 30)

Control Structures

If Statements

  • Syntax: if condition: # block of code elif condition: # another block else: # default block
  • Example: Decision making based on temperature

While Loops

  • Syntax: i = 1 while i <= 5: print(i) i += 1

For Loops

  • Iterating Over Lists: for item in [1, 2, 3]: print(item)
  • Using range Function: for number in range(5): print(number)

Data Structures

Lists

  • Definition: Using square brackets []
  • Basic Operations:
    • Accessing and modifying elements
    • Slicing
    • Methods: .append(), .insert(), .remove(), .clear()
  • Iteration: Looping through lists

Tuples

  • Immutable Lists: Using parentheses ()
  • Why Use Tuples: Ensuring data integrity when immutability is needed
  • Example: numbers = (1, 2, 3) print(numbers[0]) # prints 1

Summary and Further Learning

  • Code with Mosh: Further courses available online
    • Comprehensive Python course link below video