Python
Python Programming
Python is a popular programming language known for its simplicity and versatility. It is widely used for web development, data analysis, machine learning, and more. This tutorial will guide you through the basics of Python and help you start coding effectively.
Why Python?
- Easy to read and write
- Extensive libraries and frameworks
- Cross-platform compatibility
- Excellent community support
What is Python?
Python is an interpreted, high-level, general-purpose programming language. It was created by Guido van Rossum and first released in 1991. Python’s design philosophy emphasizes code readability with its notable use of significant indentation.
Use Cases of Python:
- Web development (Django, Flask)
- Data Science (Pandas, NumPy, Matplotlib)
- Machine Learning (Scikit-learn, TensorFlow)
- Automation (Scripting tasks)
Python Install
Many PCs and Macs will have python already installed.
To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe):
C:\Users\Your Name>python --version
To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type:
python --version
If you find that you do not have Python installed on your computer, then you can download it for free from the following website: https://www.python.org/
Python Quickstart
Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed.
The way to run a python file is like this on the command line:
C:\Users\Your Name>python helloworld.py
Understanding Python Syntax
Python syntax refers to the set of rules that defines how a Python program will be written and interpreted (by both the runtime system and human readers). Python emphasizes readability and simplicity, making it a great language for beginners and professionals alike.
-
Whitespace and Indentation: Python uses indentation to define the scope in the code, such as loops, functions, and classes. Unlike many other programming languages, indentation is not just for readability but is mandatory.
Example:
The indentation (4 spaces in the example above) is how Python groups the code inside theprint("if 5 > 2: print("Five is greater than two!")
if
statement. -
Statements: Python statements are instructions executed by the Python interpreter. Each statement should be written on a separate line, unless you are using a semicolon (
;
) to write multiple statements on the same line.
Example: