Registry Synced

Week 1: Introduction to Python and Basic Operations

478 words
2 min read
Course: Jan 2026 - Python Difficulty: Foundational Focus: Getting started, syntax basics, variables, and data types.

1. Introduction to Python

Python is a high-level, interpreted, dynamically typed programming language. It is known for its readability and concise syntax.

1.1 Why Python?

  • Easy to Learn: Syntax is similar to plain English.
  • Versatile: Used for web development, data science, automation, AI, and more.
  • Large Ecosystem: Extensive standard library and third-party packages.

1.2 The Print Function

The print() function is used to output data to the console.
python
print("Hello, World!")

2. Variables and Data Types

A variable is a named location in memory used to store data. In Python, you don't need to declare a variable's type explicitly (dynamic typing).

2.1 Naming Rules

  • Must start with a letter or underscore (_).
  • Can contain letters, numbers, and underscores.
  • Case-sensitive (Age and age are different).
  • Cannot use Python keywords (like if, while, True).

2.2 Core Data Types

  • Integer (int): Whole numbers. e.g., 10, -5
  • Float (float): Decimal numbers. e.g., 3.14, -0.01
  • String (str): Text enclosed in quotes. e.g., "Hello", 'Python'
  • Boolean (bool): Represents truth values: True or False.
You can check the type of a variable using type():
python
x = 10
print(type(x))  # Output: <class 'int'>

3. Arithmetic Operators

Python provides various operators for mathematical calculations:
  • + (Addition): 5 + 3 = 8
  • - (Subtraction): 5 - 3 = 2
  • * (Multiplication): 5 * 3 = 15
  • / (True Division): 5 / 2 = 2.5
  • // (Floor Division): Divides and rounds down to nearest integer. 5 // 2 = 2
  • % (Modulo): Returns the remainder. 5 % 2 = 1
  • ** (Exponentiation): 5 ** 2 = 25

3.1 Operator Precedence (PEMDAS)

Python evaluates expressions following standard mathematical order:
  1. Parentheses ()
  2. Exponentiation **
  3. Multiplication, Division, modulo (*, /, //, %)
  4. Addition and Subtraction (+, -)

4. Input and Type Conversion

By default, the input() function reads user input as a String.

4.1 Getting Input

python
name = input("Enter your name: ")
print("Welcome, " + name)

4.2 Type Casting (Conversion)

To perform math on user input, you must convert it to a numeric type.
python
age_str = input("Enter your age: ")
age = int(age_str)  # Converts string to integer

price = float(input("Enter price: ")) # Converts to float immediately
Attempting to convert a non-numeric string like
"hello" to an int will result in a ValueError.


Document Outline
Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.