Intro to python
Full Page ViewPython 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
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
Python Indentation
Full Page ViewIndentation 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 ViewPython 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 ViewVariables 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 ViewPython 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 ViewPython uses if, elif, and else statements to execute code based on certain conditions. Nested conditions and ternary expressions allow more complex logic.
Loops
Full Page ViewLoops 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 ViewFunctions 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 ViewModules 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 ViewPython 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 ViewExceptions 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
try:
num = 5
print(10 / num)
except ZeroDivisionError:
print("Cannot divide by zero!")
except ValueError:
print("Invalid input!")
finally:
print("Execution complete.")
Console Output