CodeDocs

Comprehensive documentation for popular programming languages

Python
HTML/CSS/JS
Java

Python Documentation

Python test

🐍 Python

Python is a high-level, interpreted, general-purpose programming language. It was created by Guido van Rossum in 1989 and first released in 1991.

Python is known for being simple, readable, and powerful. Interestingly, its name does not come from a snake, but from a British comedy show – Monty Python’s Flying Circus.




βœ… Advantages of Python (Why we use Python?)

  • Simple & Easy to Learn β†’ Syntax is like English.
  • Portable β†’ Same code runs on different operating systems.
  • Free & Open Source β†’ Anyone can use and modify it.
  • Rich Libraries β†’ Ready-made packages for Data Science, AI, Web Development, Games, etc.
  • Interpreted β†’ Runs line by line, easy to debug.
  • Object-Oriented β†’ Supports Classes & Objects.
  • Huge Community Support β†’ Easy to get help worldwide.



πŸ”Ή Uses of Python

Python is widely used for:

  • 🌐 Web Development (server-side)
  • πŸ’» Software Development
  • πŸ“Š Mathematics & Data Analysis
  • βš™οΈ System Scripting & Automation



πŸš€ What can Python do?

  • Can be used on a server to create web applications.
  • Can be integrated with software to create workflows.
  • Can connect to database systems, and also read & modify files.
  • Can handle big data and perform complex mathematics.
  • Can be used for rapid prototyping as well as production-ready software.


πŸ”Ή Python Interpreter

An Interpreter is a special program that executes Python code line by line. Unlike a compiler, which translates the entire code at once, the interpreter runs the code immediately, making Python easier to debug and test.

  • πŸ‘‰ Converts high-level Python code into machine code step by step.
  • πŸ‘‰ Executes one line at a time, which makes it slower than compiled languages but easier to understand.
  • πŸ‘‰ Examples: CPython (default Python interpreter), PyPy, Jython.

Example: If you write print("Hello"), the interpreter immediately executes and shows: Hello



πŸ”Ή IDE (Integrated Development Environment)

An IDE is a software application that provides a complete environment for coding. It combines multiple tools into one place, making programming easier and faster.

  • πŸ‘‰ Provides a code editor (to write code).
  • πŸ‘‰ Syntax highlighting (colors for keywords, variables, etc.).
  • πŸ‘‰ Debugger (to find and fix errors).
  • πŸ‘‰ Auto-completion (suggests code as you type).
  • πŸ‘‰ Project management (to handle multiple files).

Examples of IDEs for Python: PyCharm, VS Code, Spyder, IDLE (comes with Python).



✨ Difference Between Interpreter and IDE

Interpreter IDE
Executes Python code line by line. Provides tools for writing, editing, running, and debugging code.
Focuses only on running the code. Helps in the entire development process.
Example: CPython, PyPy Example: PyCharm, VS Code


πŸ–¨οΈ The print() Function in Python

The print() function is one of the most commonly used functions in Python. It is used to display output on the screen.

Syntax:

print(object(s), sep=' ', end='\n', file=sys.stdout)
  • object(s) β†’ The values you want to display.
  • sep β†’ Separator between multiple values (default: space).
  • end β†’ Defines what to print at the end (default: new line \n).
  • file β†’ Where the output should go (default: screen).

Examples:

print("Hello, Students!")  
# Output: Hello, Students!
print("Python", "is", "fun", sep="-")  
# Output: Python-is-fun
print("Hello", end=" ")
print("World")  
# Output: Hello World

πŸ’» Python Commands

A command in Python is an instruction given to the computer to perform a specific task. These commands can be written in a Python file (.py) or directly in the Python shell (IDLE/terminal).

Types of Commands:

  • Input/Output Commands β†’ print(), input()
  • Mathematical Commands β†’ +, -, *, /, %
  • Conditional Commands β†’ if, else, elif
  • Looping Commands β†’ for, while
  • Exit Command β†’ exit() or quit()

Examples:

# Input/Output
name = input("Enter your name: ")
print("Welcome", name)
# Conditional Command
x = 10
if x > 5:
    print("x is greater than 5")
# Looping Command
for i in range(3):
    print("Hello")  
# Output:
# Hello
# Hello
# Hello
program1.py
# Program 1
print("Hello, Students!")

Explanation:

This is the simplest Python program. The print() function is used to display output on the screen. In this program, it prints the text: Hello, Students!

  • print() β†’ It is a built-in Python function used to show output.
  • "Hello, Students!" β†’ This is a string written inside double quotes ("").

The output of this program will be: Hello, Students!

program2.py
# Program 2: Addition of Two Numbers
a = 10
b = 20
sum = a + b
print("The sum is:", sum)

Explanation:

This program performs the addition of two numbers in Python. It takes two numbers a = 10 and b = 20, adds them, and stores the result in the variable sum. Finally, the print() function displays the result.

  • a = 10 β†’ Variable a is assigned the value 10.
  • b = 20 β†’ Variable b is assigned the value 20.
  • sum = a + b β†’ Adds the values of a and b, then stores the result in sum.
  • print("The sum is:", sum) β†’ Prints the message along with the result.

The output of this program will be: The sum is: 30

πŸ”Ή Variables in Python

A variable in Python is a name given to a memory location where data is stored. It is like a container that holds some value which can be changed during program execution.

✨ Features of Variables:

  • πŸ‘‰ You don’t need to declare the type of variable explicitly (Python is dynamically typed).
  • πŸ‘‰ A variable is created automatically when a value is assigned to it.
  • πŸ‘‰ Variables can store different types of data like numbers, strings, lists, etc.

βœ… Rules for Naming Variables:

  • Must start with a letter or underscore (_).
  • Cannot start with a number.
  • Can only contain letters (a–z, A–Z), digits (0–9), and underscores.
  • Case-sensitive β†’ name, Name, and NAME are different variables.
  • Should not use reserved keywords (like if, class, while).

πŸ“Œ Examples:

# Assigning values to variables
x = 10            # integer
name = "Python"   # string
pi = 3.14         # float
is_active = True  # boolean

print(x)          # Output: 10
print(name)       # Output: Python
print(pi)         # Output: 3.14
print(is_active)  # Output: True

πŸ”„ Changing Variable Values:

x = 5
print(x)   # Output: 5

x = "Hello"
print(x)   # Output: Hello

πŸ‘‰ Here, the same variable x first stores a number and then a string, which shows Python is dynamically typed.

πŸ†” Getting Memory Address of Variable:

a = 50
print(id(a))  # Shows unique memory address where 'a' is stored
program_variable1.py
# Example 1: Assigning values to variables
x = 10
name = "Python"
pi = 3.14
is_active = True

print(x)          # Output: 10
print(name)       # Output: Python
print(pi)         # Output: 3.14
print(is_active)  # Output: True
program_variable2.py
# Example 2: Changing variable values
x = 5
print(x)   # Output: 5

x = "Hello"
print(x)   # Output: Hello
program_variable3.py
# Example 3: Getting memory address of a variable
a = 50
print(id(a))  # Shows unique memory address of 'a'

Python Data Types

In Python, data types define the type of value a variable can hold. Python is dynamically typed, which means you don’t need to declare the type explicitly – it is decided at runtime.

Major Built-in Data Types in Python:

  • Numeric Types: int, float, complex
  • Sequence Types: str, list, tuple
  • Mapping Type: dict
  • Set Types: set, frozenset
  • Boolean Type: bool
  • Binary Types: bytes, bytearray, memoryview
  • None Type: NoneType

datatype_numeric.py
# Numeric Types
x = 10            # int
y = 3.14          # float
z = 2+3j          # complex

print("x is", x, "Type:", type(x))
print("y is", y, "Type:", type(y))
print("z is", z, "Type:", type(z))
datatype_sequence.py
# Sequence Types
name = "Python"      # String
fruits = ["apple", "banana", "cherry"]   # List
numbers = (1, 2, 3)                # Tuple

print(name, type(name))
print(fruits, type(fruits))
print(numbers, type(numbers))
datatype_dict.py
# Dictionary
student = {
    "name": "Alice",
    "age": 21,
    "grade": "A"
}

print(student)
print("Name:", student["name"])
datatype_boolean_none.py
# Boolean and NoneType
is_active = True
is_admin = False
nothing = None

print(is_active, type(is_active))
print(is_admin, type(is_admin))
print(nothing, type(nothing))

Python Data Types (Detailed Explanation)

In Python, every value has a specific data type. It tells the interpreter how the value should be stored and what operations can be performed on it.

1. Numeric Types

  • int β†’ Whole numbers (positive or negative) without decimals. Example: 10, -25
  • float β†’ Decimal numbers. Example: 3.14, -7.5
  • complex β†’ Numbers with real and imaginary parts. Example: 2+3j
numeric_example.py
# Numeric Types
x = 10          # int
y = 3.14        # float
z = 2+3j        # complex

print(x, type(x))
print(y, type(y))
print(z, type(z))

2. String (str)

A string is a sequence of characters enclosed in single (' '), double (" ") or triple (''' ''' / """ """) quotes.

string_example.py
# String Example
name = "Python"
greet = 'Hello'
multiline = """This 
is 
multiline"""

print(name)
print(greet)
print(multiline)

3. List

A list is an ordered, mutable (changeable) collection of items. It can hold different data types in one list.

list_example.py
# List Example
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3, 4]

fruits.append("mango")
print(fruits)
print(numbers[2])

4. Tuple

A tuple is an ordered, immutable (unchangeable) collection of items. Once created, elements cannot be modified.

tuple_example.py
# Tuple Example
coordinates = (10, 20)
colors = ("red", "blue", "green")

print(coordinates)
print(colors[1])

5. Dictionary (dict)

A dictionary is an unordered collection of key-value pairs. Keys must be unique and immutable.

dict_example.py
# Dictionary Example
student = {
    "name": "Alice",
    "age": 21,
    "grade": "A"
}

print(student)
print(student["name"])

6. Set

A set is an unordered collection of unique items (no duplicates).

set_example.py
# Set Example
numbers = {1, 2, 2, 3}
letters = set(['a', 'b', 'c'])

print(numbers)   # duplicates removed
print(letters)

7. Boolean (bool)

A boolean represents one of two values: True or False.

bool_example.py
# Boolean Example
is_active = True
is_admin = False

print(is_active)
print(is_admin)

8. None Type

None represents the absence of a value or a null value. Its type is NoneType.

none_example.py
# None Example
result = None

print(result)
print(type(result))

⚑ Python Mathematical (Arithmetic) Operations

Python supports many mathematical operations. These operators are used to perform calculations on numbers.

πŸ“Œ Types of Arithmetic Operators

Operator Symbol Description Example
Addition + Adds two numbers 10 + 5 = 15
Subtraction - Subtracts right operand from left 10 - 5 = 5
Multiplication * Multiplies two numbers 10 * 5 = 50
Division / Divides left by right (always float result) 10 / 5 = 2.0
Floor Division // Divides and gives integer part only 10 // 3 = 3
Modulus % Returns remainder 10 % 3 = 1
Exponent ** Power (xy) 2 ** 3 = 8

βœ… Example Programs

addition.py
# Addition
a = 10
b = 5
print("Sum:", a + b)   # Output: 15
subtraction.py
# Subtraction
x = 20
y = 8
print("Difference:", x - y)   # Output: 12
multiplication.py
# Multiplication
m = 6
n = 7
print("Product:", m * n)   # Output: 42
division.py
# Division and Floor Division
a = 10
b = 3

print("Division:", a / b)    # Output: 3.333...
print("Floor Division:", a // b)  # Output: 3
modulus_exponent.py
# Modulus and Exponent
print(10 % 3)     # Output: 1
print(2 ** 5)     # Output: 32
program3.py
# Program 3: Check Even or Odd
num = int(input("Enter a number: "))

if num % 2 == 0:
    print(num, "is Even")
else:
    print(num, "is Odd")

Explanation:

This program checks whether a number entered by the user is even or odd. The user inputs a number, then the program uses the modulus operator (%) to check divisibility by 2.

  • num = int(input("Enter a number: ")) β†’ Takes input from the user, converts it into an integer, and stores it in num.
  • if num % 2 == 0: β†’ If the number is divisible by 2, it is even.
  • else: β†’ Otherwise, the number is odd.
  • print() β†’ Displays whether the number is even or odd.

Example Outputs:
If input is 10 β†’ Output: 10 is Even
If input is 7 β†’ Output: 7 is Odd

program4.py
# Program 4: Multiplication Table
num = int(input("Enter a number: "))

for i in range(1, 11):
    print(num, "x", i, "=", num * i)
program5.py
# Program 5: Fibonacci Series
def fibonacci(n):
    a, b = 0, 1
    count = 0
    while count < n:
        print(a, end=" ")
        nth = a + b
        a = b
        b = nth
        count += 1

fibonacci(10)
example.py
# Python program to display Fibonacci series
def fibonacci(n):
    # First two terms
    a, b = 0, 1
    count = 0
    
    # Check if the number of terms is valid
    if n <= 0:
        print("Please enter a positive integer")
    elif n == 1:
        print("Fibonacci sequence up to", n, ":")
        print(a)
    else:
        print("Fibonacci sequence:")
        while count < n:
            print(a, end=' ')
            nth = a + b
            a = b
            b = nth
            count += 1

# Call the function
fibonacci(10)

Simple Syntax

Python has a straightforward syntax that emphasizes readability and reduces the cost of program maintenance.

Extensive Libraries

Python's standard library is large and comprehensive, offering modules for everything from web development to data science.

Community Support

Python has a large and active community that contributes to an extensive ecosystem of frameworks and tools.

HTML, CSS & JavaScript Documentation

HTML Test

HTML, CSS, and JavaScript are the core technologies of web content. HTML provides the structure, CSS the styling, and JavaScript the behavior.

example.html
<!-- Simple HTML page with CSS and JavaScript -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .btn {
            background: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Hello World!</h1>
        <button class="btn" id="myBtn">Click Me</button>
    </div>
    
    <script>
        // JavaScript code
        document.getElementById('myBtn').addEventListener('click', function() {
            alert('Button clicked!');
        });
    </script>
</body>
</html>

HTML Structure

HTML (HyperText Markup Language) is the standard markup language for documents designed to be displayed in a web browser.

CSS Styling

CSS (Cascading Style Sheets) is used to describe the presentation of a document written in HTML or XML.

JavaScript Interactivity

JavaScript is a programming language that enables interactive web pages and is an essential part of web applications.

Java Documentation

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

Example.java
// Java program to demonstrate a simple class
public class Student {
    
    // Fields
    private String name;
    private int age;
    
    // Constructor
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    
    // Method to display student information
    public void displayInfo() {
        System.out.println("Student Name: " + this.name);
        System.out.println("Student Age: " + this.age);
    }
    
    // Main method
    public static void main(String[] args) {
        // Create a Student object
        Student student1 = new Student("John Doe", 20);
        
        // Call display method
        student1.displayInfo();
    }
}

Object-Oriented

Java is fundamentally object-oriented, which helps in creating modular programs and reusable code.

Platform Independent

Java code is compiled into bytecode that can run on any device with a Java Virtual Machine (JVM).

High Performance

Java's Just-In-Time (JIT) compiler enables high performance by compiling bytecode to native machine code at runtime.