0% found this document useful (0 votes)
3 views44 pages

500 Programming & Software 06 Python UNIX

The document provides an overview of various programming styles supported by Python, including Object-Oriented, Procedural, and Functional programming, among others. It also discusses Python's unique features such as dynamic typing and automatic memory management, as well as best practices for setting up Python development environments using tools like VS Code and Jupyter Notebook. Additionally, it covers package management with Conda and PIP, highlighting the importance of environment isolation and dependency management.

Uploaded by

naserfeysal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views44 pages

500 Programming & Software 06 Python UNIX

The document provides an overview of various programming styles supported by Python, including Object-Oriented, Procedural, and Functional programming, among others. It also discusses Python's unique features such as dynamic typing and automatic memory management, as well as best practices for setting up Python development environments using tools like VS Code and Jupyter Notebook. Additionally, it covers package management with Conda and PIP, highlighting the importance of environment isolation and dependency management.

Uploaded by

naserfeysal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

500 - Programming &

Software - Python
Review Linux Lectures of Pytopia
Review Git Lectures of Pytopia
Search Aircarft and components of Aeronautics in Python [Link]
Programming Styles
Object-Oriented Programming (OOP):
Python supports object-oriented programming (OOP) paradigms, allowing developers to create reusable and modular code. With classes, objects, and inheritance, you can structure your code in a
way that reflects real-world objects and relationships. OOP principles facilitate code organization, encapsulation, and abstraction, making it easier to build and maintain complex projects.

1. Object-Oriented Programming (OOP)


Key Features: Organizes code into objects that combine data (attributes) and behavior (methods).
Core Concepts: Encapsulation, Inheritance, Polymorphism, Abstraction.
Examples: Java, C++, Python (supports OOP), Ruby.
2. Procedural Programming
Key Features: Organizes code into procedures or functions that execute sequentially.
Core Concepts: Modularity, Reusability, Top-down approach.
Examples: C, Pascal, Fortran.
3. Functional Programming
Key Features: Treats computation as the evaluation of mathematical functions and avoids mutable state.
Core Concepts: Pure functions, First-class functions, Immutability, Recursion.
Examples: Haskell, Lisp, Scala, JavaScript (supports functional programming).
4. Declarative Programming
Key Features: Focuses on what the program should accomplish rather than how to accomplish it.
Core Concepts: High-level descriptions, no explicit control flow.
Examples: SQL, HTML, CSS, Prolog.
5. Imperative Programming
Key Features: Focuses on how to perform tasks by using statements that change a program's state.
Core Concepts: Explicit control flow, Mutability, Sequence of commands.
Examples: Assembly language, C, Python (supports imperative programming).
6. Event-Driven Programming
Key Features: Flow of the program is determined by events such as user actions, sensor outputs, or messages.
Core Concepts: Event handlers, Event loop, Callbacks.
Examples: JavaScript (for web development), C# (Windows Forms), Python (Tkinter).
7. Logic Programming
Key Features: Based on formal logic, programs consist of a set of facts and rules.
Core Concepts: Predicates, Backtracking, Logical inference.
Examples: Prolog, Datalog.
8. Aspect-Oriented Programming (AOP)
Key Features: Focuses on separating cross-cutting concerns, such as logging or security, from the main logic.
Core Concepts: Aspects, Join points, Advice.
Examples: AspectJ, Spring AOP.
9. Component-Based Programming
Key Features: Builds software by combining reusable components.
Core Concepts: Modularization, Component reusability.
Examples: React (JavaScript), Angular, Unity (C#).
10. Reactive Programming
Key Features: Focuses on asynchronous data streams and propagating changes.
Core Concepts: Observables, Streams, Data flow, Event-driven.
Examples: RxJS, Reactor (Java), Flutter (Dart).
11. Data-Oriented Programming
Key Features: Focuses on organizing and processing data efficiently, separating behavior from data structure.
Core Concepts: Data-driven design, Immutability.
Examples: SQL, pandas (Python).
12. Concurrent Programming
Key Features: Emphasizes multiple processes or threads executing simultaneously.
Core Concepts: Threads, Locks, Synchronization.
Examples: Go (goroutines), Java (concurrency APIs).
13. Parallel Programming
Key Features: Focuses on performing multiple computations simultaneously using multiple processors or cores.
Core Concepts: Parallelism, Multithreading, SIMD/MIMD.
Examples: CUDA (for GPUs), OpenMP, MPI.
14. Metaprogramming
Key Features: Writing programs that can manipulate or generate other programs.
Core Concepts: Reflection, Code generation.
Examples: Python (with decorators), Lisp (macros).
15. Scripting
Key Features: Writing short programs to automate tasks or glue together other programs.
Core Concepts: Interpreted execution, Rapid development.
Examples: Bash, Perl, Python, Ruby.
Choronolography of Programming Languages
Level of Languages
Text Editor vs. IDE
Python - Unique Features
Dynamic Typing vs. Static Typing:
- in Python a variable does not need to explicitly declare;
- n = 5 but next line n = ''quat'' and in next line n = [1, 2, 3]
- buy in C static typing and no chnage is possible

Automatic Memory Management:


- In C need preallocation, reallocation and delete
- In python no need to do, as you assign a variable it is allocated or reallocated or deleted
Python - Versions
Python-2:
Is not supported longer

Backward Compatibility:
Python 2 Python 2.3 Python 2.6 are all interoperable
Python 2 Python 3 are not interoperable which means is not Backwards compatible
Best Python Setup
VS Code
- Visual Studio Code the most famous Text Editor designed by Microsoft
- Offers robust features for Python development, including syntax highlighting, code completion,
debugging support, version control integration

Jupyter Notebook
Jupyter Notebook is an interactive computing environment that allows users to create and share
documents containing live code, visualizations, explanatory text, and more. It is particularly useful
for data analysis, exploratory programming, and documentation purposes. It is a REPL
environment stands for "Read, Evaluate, Print, and Loop". It's an acronym that refers to a
computer programming environment that allows users to input commands, execute them, and
view the results. REPLs are also known as interactive toplevels or language shells

Conda
- A popular package manager and environment management system for Python and other
programming languages.
- It simplifies the process of installing, managing, and organizing packages and dependencies
within isolated environments, ensuring reproducibility and avoiding conflicts between different
projects.

It Is to Work from Terminal


1-Linux & Mac
They both are UNIX based and have terminal

2-Windows
Windows brought core of Linux to Windows from W8
No need to have virtual environment in Windows to have Linux in W8 and later
If one use Windows Subsystem for Linux (WSL) it will be in Linux environment
Powershell is terminal of Windows not used in our programming
Jupyterlab - Commands
Commands:
shift+enter Run the cell and goes to next cell
control+enter Run the current cell
alt+enter Run the current cell and makes an empty cell next
VS Code - Commands
Commands:
code Opens VS Code
code . Opens VS code in current directory
code /xx/xx/[Link] Opens the file with VS Code
Note: If VS Code is already opened in a project folder, and you want to open another project, new VS Code will be
opened but if you only open a file, it will be opened in current project

alt+up or down inside VS Code - Move the entire line up or down in VS Code
ctr+shift+p inside VS Code - Opens Coomand Palletes

Auto Save
- Activate it in file tab after installation because it is not active
- This way as you type no saving is needed and it is always saved as edited
Package Management
Package Management Package Management Benefits
When you write Python code, it often relies on external libraries or tools to perform specific By using Conda and environments, Python developers achieve code portability and
tasks, like handling data, plotting graphs, or connecting to databases. These external libraries reproducibility. Portability means that the code can be easily shared and run on different
are called packages. Think of them as ready-to-use modules that extend Python's capabilities computers, as long as the recipient sets up the same Conda environment. Reproducibility
and save you time by providing pre-built functionality. ensures that the code will behave consistently over time, even if package versions change, as
Conda keeps track of dependencies and versions within the environment.
Now, imagine you're a Python developer working on a project that uses several packages. The
challenge arises when different projects might require different versions of the same package A package manager, such as Conda, provides several benefits for Python development:
or even entirely different sets of packages. If you install all these packages globally on your
computer, you may encounter conflicts, where one project needs an older version of a Dependency management: Package managers handle the installation, upgrading, and
package, while another requires a newer version. removal of packages and their dependencies. This eliminates the need to manually manage
complex dependency chains, ensuring that your project's dependencies are correctly installed
Here's where environments and package managers come to the rescue: and compatible with each other.

Package Versions: Packages can have multiple versions, each with its own set of features, Environment isolation: With Conda, you can create isolated environments, also known as
bug fixes, and changes. However, not all projects may be compatible with the latest versions virtual environments, for your Python projects. Each environment can have its own set of
of packages they rely on. Therefore, it's crucial to manage specific package versions to packages and dependencies, enabling you to work on different projects with varying
maintain code stability and prevent unexpected behavior. requirements without conflicts.

Environment: An environment is like a self-contained workspace for a Python project. It Reproducibility: By specifying the exact versions of packages in your Conda environment,
allows developers to isolate their project from the global Python installation and other you can ensure that your project can be reproduced in the future. This is particularly useful
projects. This isolation helps avoid conflicts between different projects that might rely on when sharing code with others or when deploying your project on different machines.
different package versions or have conflicting dependencies.

Package Manager: A package manager is a tool that simplifies the process of installing,
updating, and removing packages within a specific environment. It keeps track of package
versions and ensures that the required packages are available to the project when needed.
Package Management - Conda vs. PIP
Package Repository:
- Where Packages Are Uploaded, These are the sources
where the package managers fetch the packages from. PyPI
(Python Package Index) is the repository for pip, while
Anaconda Channels are for conda.
- [Link] is Package Repository of for pip
- Conda-Forge Is the Main package of Conda
- Conda Uses many Channels of Repositories
Conda - Commands
Commands
conda create --name my_env python=3.10 Creates new environment and installs python 3.1
conda env remove --name my_env Removes my_env environment
conda activate my_env Activates my_env environment
conda deactivate Deactivates current environment
conda env list Lists all avilable environment
conda info --envs Lists all avilable environment
conda list Lists all th packages installed in curret environment
conda install PACKAGE_NAME installs specific package in current environment
conda install numpy=1.25 Example
conda update PACKAGE_NAME Updates specific package in current environment
conda update --all Updates all package in current environment
conda remove PACKAGE_NAME Removes specific package in current environment
Coding in VS Code Practice
1-Make a new environment
conda create --name my_env python=3.10
2-Activate new environment with conda
conda activate my_env
3-install a jupyter lab with conda
conda install jupyterlab
4-code . to open vs code
code .
input/output
input:
- always receives string
- if you want integer or float you have to explicitly convert after inputing
- input(“Comment”)
- input() is string even if you get integer, to convert it to integer int(input())
- when entering value or text no “” or '' is needed

print:
- print(“Comment”, variable)
- print(variable)
- print add space after each item
Simple Data Types:
Data Type
- Number
Integer
Float
Complex
- String
- Boolean
Composite Data Types:
- List
- Tuple
- Set
- Dictionary

Simple Data Types in Python:


Data Type - Integer/Float Commands
Infinity & Smallest in Python:

Approximation of Floating in Python:


Data Type - Operators
Variable Name Rules:
Variable & Object
never start with number
case sensitive in Python: age Age are different
never use -
can be started with _
use full capital for constant as a convention

dir(variable) list all the mothods available for object


Variable & Object - is vs. ==
Output Format Before Python 3.6
Data Type - String Useful Commands
Commands
use “text” for string
or use 'text'
or use “””text”””
to have ' in text use \' or use “text” in string or triple quot
to have ” in text use \” or use 'text' in string or triple quot

Escape Sequencing

Output Format After Python 3.6


Data Type - String Useful Commands

CommandsNote:
: means to end
[:5] means from first to character number 5
[5:] means from character number 5 to end
[::5] means from first to end with step 5
Data Type - Mutable vs. Immutable
Data Type - List Creating
Data Type - List Editing
Data Type - List Operation
Data Type - Tuple Commands Note:
index & count as in List
membership, concatnation and repetition s in List
Data Type - Dictionary
Data Type - Dictionary
Data Type - Dictionary Commands Note:
membership as in List
+ for concatnation and * for multiplication not available
as in List
Data Type - Dictionary - Nested Commands Note:
membership as in List
+ for concatnation and * for multiplication not available
as in List
Data Type - Set
Data Type - Set
Data Type - Set Commands Note:
the comment is not right, both can can take multiple stes
Data Type - Frozenset
Data Type - Frozenset
Data Type - Packing & Unpacking
Python Structure & Syntax
Python - Control Structure - If
Commands Note:
Break leaves the loop
Continue skips at that line and goes to first line of loop
Pass used as a blank exection when a txt should be written
otherwise error is published
Python - Control Structure - For

Commands Note:
Break leaves the loop
Continue skips at that line and goes to first line of loop
Pass used as a blank exection when a txt should be written
otherwise error is published
Python - Control Structure - While

Commands Note:
Break leaves the loop
Continue skips at that line and goes to first line of loop
Pass used as a blank exection when a txt should be written
otherwise error is published
Data Type - File
Data Type - File
Data Type - File

You might also like