🐍

Introduction to Python Programming Basics

Aug 25, 2024

Python Programming Lecture Notes

Introduction to Python

  • Python is easy to learn and the most popular programming language.
  • New Python developers earn an average salary of $64,000 in the U.S.

Installing Python

  1. Download Python from python.org/downloads.
  2. Check "Add Python 3.9 to PATH" during installation.
  3. Complete installation and confirm success.

Integrated Development Environment (IDE)

  • Recommended IDE: PyCharm.
  1. Download PyCharm from jetbrains.com/pycharm.
  2. Follow standard installation procedures.

Creating Your First Project

  • Create a new project in PyCharm, name it HelloWorld.
  • Create a new Python file named main.py.
  • First line of code: print("I love pizza").
  • Run the script to see output in the terminal.

Python Variables and Data Types

Variables

  • A variable is a container for a value.
  • Variables can hold different data types (strings, integers, booleans, etc.).

Data Types

  1. Strings: Use single or double quotes.
    • Example: name = "Bro"
  2. Integers: Whole numbers.
    • Example: age = 21
  3. Floats: Decimal numbers.
    • Example: height = 175.5
  4. Booleans: True or False.
    • Example: is_human = True

Creating Variables

  • Define a variable: name = "Bro".
  • Print name to the console: print(name).

Using IDE Features

  • Change font size and color in PyCharm to enhance visibility.

Functions

  • Create functions for repetitive tasks.
  • Example: def greet(name): print(f"Hello, {name}!")

Control Structures

If Statements

  • Check conditions and execute blocks based on truthiness.
  • Syntax: if condition: # code to execute

Loops

  • Use loops to iterate over data structures.
  • Example: for i in range(10): print(i).

Object-Oriented Programming

  • Create classes to define objects with attributes and methods.
  • Example: class Dog: def bark(self): print("Woof!")

GUI Programming

Creating Windows

  • Use Tkinter to create graphical user interfaces.
  • Example: from tkinter import Tk and window = Tk().

Widgets

  • Add widgets like buttons, labels, and text areas to your GUI.
  • Example: button = Button(window, text="Click Me")

Event Handling

  • Bind functions to events (e.g., button clicks).
  • Example: button.config(command=my_function).

Summary

  • Python is a versatile programming language with various applications.
  • Understanding data types, functions, and object-oriented programming is crucial.
  • Tkinter allows for GUI development in Python.