Python Basics

Python Installation:

  • Download: Visit the official Python website (python.org) to download the latest version of Python.
  • Operating System: Choose the appropriate installer for your operating system (Windows, macOS, Linux).
  • Installation Steps: Run the installer, follow the prompts, and select options like adding Python to PATH.
  • Verify Installation: Open a command prompt or terminal and type python --version to verify the installation.

IDLE (Integrated Development and Learning Environment):

  • IDLE: IDLE is Python’s default interactive development environment.
  • Features: IDLE provides a Python shell for interactive coding, code highlighting, and simple debugging.
  • Running Code: Type or paste code into the shell and press Enter to execute.
  • Scripting: You can also write and run longer scripts using the IDLE editor.

What is Python:

  • Python: Python is a high-level, interpreted programming language known for its simplicity and readability.
  • General Purpose: Python is a versatile language used for web development, data analysis, artificial intelligence, and more.
  • Syntax: Python’s syntax emphasizes code readability with its use of indentation and minimalistic syntax.
  • Object-Oriented: Python supports object-oriented, procedural, and functional programming paradigms.
  • Community and Libraries: Python has a large and active community, along with a vast ecosystem of libraries and frameworks.

Math Operators:

  • Addition (+): Used to add two or more numeric values. Example: result = 5 + 3
  • Subtraction (-): Used to subtract one numeric value from another. Example: difference = 10 - 4
  • Multiplication (*): Used to multiply two or more numeric values. Example: product = 3 * 7
  • Division (/): Used to divide one numeric value by another. Example: quotient = 15 / 3
  • Modulus (%): Returns the remainder of division between two numbers. Example: remainder = 10 % 3
  • Exponentiation (**): Raises a number to the power of another number. Example: result = 2 ** 4

Strings:

  • String: A sequence of characters enclosed in single or double quotes. Example: message = "Hello, world!"
  • Concatenation: Combining strings using the + operator. Example: full_name = "John" + " " + "Doe"
  • String Length: Finding the number of characters in a string using len(). Example: length = len("Python")
  • Indexing: Accessing individual characters in a string by their position. Example: first_char = "Hello"[0]
  • Slicing: Extracting a portion of a string using indices. Example: substring = "Python"[1:4]

Variables:

  • Variable: A name that holds a value in memory. Example: age = 25
  • Variable Assignment: Giving a value to a variable using = symbol. Example: name = "Alice"
  • Variable Naming: Following naming rules (letters, numbers, underscores) and conventions (lowercase, meaningful names). Example: user_count = 100

Data Types:

  • Integer: A whole number data type. Example: count = 5
  • Float: A decimal number data type. Example: pi = 3.14
  • String: A sequence of characters data type. Example: greeting = "Hello"
  • Boolean: A data type representing True or False values. Example: is_valid = True
  • List: An ordered collection of items. Example: numbers = [1, 2, 3, 4]
  • Tuple: An immutable ordered collection of items. Example: coordinates = (10, 20)

If Statements:

  • If Statement: Executes code based on a condition. Example: if x > 10:
  • Else Statement: Provides an alternative code path. Example: else:
  • Elif Statement: Used for multiple condition checks. Example: elif score >= 80:

Loops:

  • For Loop: Iterates over a sequence and executes code for each item. Example: for number in [1, 2, 3]:
  • While Loop: Repeatedly executes code as long as a condition is true. Example: while count < 5:
  • Range Function: Generates a sequence of numbers. Example: for i in range(5):
  • Break Statement: Terminates a loop prematurely. Example: if number == 3: break
  • Continue Statement: Skips the current iteration. Example: if number == 3: continue
What are your feelings