Intro to python

Full Page View

Python is a popular, high-level programming language created by Guido van Rossum in 1991. It is widely used for web development, software development, mathematics, system scripting, and data analysis. Python allows developers to build web applications, automate workflows, connect to databases, manipulate files, handle big data, and perform complex computations. It is cross-platform, has a simple and readable English-like syntax, requires fewer lines of code, and executes code immediately via an interpreter. Python supports procedural, object-oriented, and functional programming. Its syntax relies on indentation and new lines rather than braces or semicolons, making it especially readable. Python 3 is the latest major version and can be written in text editors or IDEs such as Thonny, PyCharm, NetBeans, or Eclipse.

</> Practice Examples

Intro To Python
Python is a popular, high-level programming language created by Guido van Rossum in 1991. It is widely used for web development, software development, mathematics, system scripting, and data analysis. Python allows developers to build web applications, automate workflows, connect to databases, manipulate files, handle big data, and perform complex computations. It is cross-platform, has a simple and readable English-like syntax, requires fewer lines of code, and executes code immediately via an interpreter. Python supports procedural, object-oriented, and functional programming. Its syntax relies on indentation and new lines rather than braces or semicolons, making it especially readable. Python 3 is the latest major version and can be written in text editors or IDEs such as Thonny, PyCharm, NetBeans, or Eclipse.

Console Output

tesrttt

Python Indentation

Full Page View

Indentation refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.

Python uses indentation to indicate a block of code.

Python Statements

Full Page View

Python statements are instructions that the interpreter can execute. Each statement typically ends with a new line, unlike other languages that use semicolons. Python supports simple statements (like assignments or function calls) and compound statements (like if, for, while, and def) that contain indented blocks. Indentation is used to define the scope of loops, functions, and classes, making Python code readable and structured.

Variables and Data Types

Full Page View

Variables are used to store data, and Python supports various data types like integers, floats, strings, booleans, lists, tuples, sets, and dictionaries. Python is dynamically typed, meaning you don’t need to declare the type explicitly.

Operators

Full Page View

Python provides operators for arithmetic, comparison, logical, assignment, membership, and identity operations. These operators allow you to perform calculations, compare values, and control the logic of your programs.

Conditional Statements

Full Page View

Python uses if, elif, and else statements to execute code based on certain conditions. Nested conditions and ternary expressions allow more complex logic.

Loops allow you to execute a block of code multiple times. Python has for loops for iteration and while loops for conditional repetition. You can control loops using break, continue, and pass.

Functions

Full Page View

Functions are blocks of code designed to perform a specific task and can be reused. Python supports positional, keyword, default, and variable-length arguments, and functions can return values.

Module and Packages

Full Page View

Modules are Python files containing functions and variables. Packages are collections of modules. You can import standard libraries or create your own modules to organize code.

File Handling

Full Page View

Python can read from and write to files using the open() function. Using the with statement ensures files are properly closed after use.

Exception Handling

Full Page View

Exceptions occur when an error happens during program execution. Python handles these errors using try-except-finally blocks, allowing the program to continue running safely.

</> Practice Examples

Exception Handling
try:
    num = 5
    print(10 / num)
except ZeroDivisionError:
    print("Cannot divide by zero!")
except ValueError:
    print("Invalid input!")
finally:
    print("Execution complete.")

Console Output

2.0