KEMBAR78
Programming Basics | PDF | Python (Programming Language) | C++
0% found this document useful (0 votes)
14 views11 pages

Programming Basics

Python is a high-level, interpreted programming language known for its readability, versatility, and dynamic typing. It has evolved through several versions since its creation in 1991, with Python 3.x being the current version that includes significant improvements. Python is widely used in various fields such as web development, data science, and automation, and it supports a rich ecosystem of libraries and frameworks.

Uploaded by

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

Programming Basics

Python is a high-level, interpreted programming language known for its readability, versatility, and dynamic typing. It has evolved through several versions since its creation in 1991, with Python 3.x being the current version that includes significant improvements. Python is widely used in various fields such as web development, data science, and automation, and it supports a rich ecosystem of libraries and frameworks.

Uploaded by

DINESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Nature of Python

Python is a high-level, interpreted, general-purpose programming language. Its nature can be


summarized as:

 High-level language → Easy to read, write, and understand (closer to human language).

 Interpreted → Executes line by line using an interpreter (no need for compilation like
C/C++).

 Object-Oriented → Supports classes, objects, inheritance, and polymorphism.

 Dynamically Typed → No need to declare variable types; Python detects them at


runtime.

 Cross-platform → Works on Windows, macOS, Linux, etc.

 Extensible & Embeddable → Can integrate with other languages like C/C++.

 Rich Standard Library → Provides built-in modules for math, file handling, networking,
etc.

 Open Source → Freely available and maintained by the Python Software Foundation
(PSF).

 Versatile → Used in Web Development, AI/ML, Data Science, Automation, IoT, etc.

Python Versions

Python has evolved a lot since its creation (1991 by Guido van Rossum).
Main milestones:

1. Python 1.x (1991–2000)

 First official release (1991).

 Basic data types, functions, error handling.

2. Python 2.x (2000–2020)

 Introduced list comprehensions, garbage collection, Unicode support (2.0).

 Widely used but had inconsistencies (like print as a statement).

 End of life: January 1, 2020 → no longer supported.

3. Python 3.x (2008–present)


 Current and future version of Python.

 Major improvements:

o print() as a function

o Unicode by default (str)

o Division operator (/ vs //) clarified

o f-strings, async/await, type hints, pattern matching, etc.

Popular Releases:

 Python 3.6 → f-strings, formatted string literals.

 Python 3.7 → data classes, context variables.

 Python 3.8 → walrus operator (:=).

 Python 3.9 → type hint improvements, string methods.

 Python 3.10 → structural pattern matching (match-case).

 Python 3.11 → faster execution (10–60%), better error messages.

 Python 3.12 (latest stable) → released Oct 2023, with optimizations and new typing
features.

Check if Python is Already Installed

 Open Command Prompt / Terminal and type:

 python --version

or

python3 --version

 If installed, it will show version (e.g., Python 3.12.0).

 If not installed → proceed with installation.


2. Download Python

 Go to the official website: https://www.python.org/downloads/

 Choose the latest stable version (e.g., Python 3.12.x).

 Installers are available for Windows, macOS, Linux.

3. Install Python on Windows

1. Download the .exe installer.

2. Run it → Important: Tick the option “Add Python to PATH”.

3. Select Install Now (recommended).

4. After installation, check:

5. python --version

4. Install Python on macOS

 macOS often comes with Python preinstalled (usually outdated).

 To install latest version:

1. Download .pkg installer from Python.org.

2. Run installer → follow steps.

3. Verify:

4. python3 --version

(Alternatively, install via Homebrew: brew install python)

5. Install Python on Linux (Ubuntu/Debian)

Most Linux distros already include Python. To update or install:

sudo apt update

sudo apt install python3

Check version:
python3 --version

6. Verify Installation

 Run Python in terminal:

 python

or

python3

 You should see the interactive shell (>>>). Example:

 >>> print("Hello, Python!")

 Hello, Python!

7. Install pip (Python Package Manager)

 pip usually comes with Python 3.x. Check:

 pip --version

 If not installed (Linux/macOS):

sudo apt install python3-pip

🔹 What is Python?

 Python is a high-level, interpreted, general-purpose programming language.

 Created by Guido van Rossum in 1991.

 Known for its simplicity, readability, and versatility.

🔹 Key Features of Python

 Easy to Learn & Use → Simple syntax close to English.

 Interpreted → Runs line by line (no compilation needed).

 Dynamically Typed → No need to declare variable types.

 Object-Oriented → Supports classes and objects.


 Cross-Platform → Works on Windows, macOS, Linux.

 Large Standard Library → Ready-to-use modules for math, files, networking, etc.

 Open Source → Free and community-driven.

 Extensible → Can integrate with C, C++, Java, etc.

🔹 Applications of Python

Python is used in almost every domain of computing:

 Web Development → Django, Flask, FastAPI

 Data Science & AI/ML → Pandas, NumPy, TensorFlow, Scikit-learn

 Automation/Scripting → Task automation, web scraping (Selenium, BeautifulSoup)

 Game Development → Pygame

 GUI Applications → Tkinter, PyQt

 Networking & IoT → Socket programming, MicroPython

 Cybersecurity → Ethical hacking, penetration testing

 Scientific Computing → SciPy, Matplotlib

🔹 Python Versions

 Python 1.x (1991–2000) – first version

 Python 2.x (2000–2020) – popular, but now retired

 Python 3.x (2008–present) – current and future version

🔹 Basic Python Syntax Example

# Hello World program

print("Hello, Python!")

# Variables
name = "Sharanya"

age = 25

# Conditional

if age >= 18:

print(name, "is an adult")

# Loop

for i in range(5):

print("Number:", i)

# Function

def greet(person):

return "Hello, " + person

print(greet(name))

🔹 Advantages of Python

✔ Simple and beginner-friendly


✔ Huge community support
✔ Rich ecosystem of libraries and frameworks
✔ Portable and flexible

🔹 Limitations of Python

✘ Slower than compiled languages (C, C++)


✘ Not ideal for mobile app development
✘ Uses more memory compared to low-level languages
Introduction to Jupyter Notebook

🔹 What is Jupyter Notebook?

 Jupyter Notebook is an open-source, interactive computing environment.

 It allows you to create and share documents that contain:


✅ Live code
✅ Equations (using LaTeX)
✅ Visualizations (charts, plots)
✅ Explanatory text (Markdown)

 The name Jupyter comes from Julia, Python, and R (three languages it was first designed
for).

 Most commonly used with Python, especially in Data Science, Machine Learning, and
Research.

🔹 Key Features

 Interactive Coding → Run code cells step by step.

 Visualization Support → Displays graphs, plots, images inline.

 Markdown Support → Add formatted text, headings, bullet points.

 Rich Media → Can embed images, videos, HTML.

 Kernel-based Execution → Supports many languages (Python, R, Julia, etc.).

 Notebook Format (.ipynb) → Saves code + output + text together.

🔹 Installation

1. Install Python first.

2. Install Jupyter using pip:

3. pip install notebook

Or, install Anaconda Distribution (recommended for beginners) → It includes Python, Jupyter,
and data science libraries pre-installed.
🔹 Starting Jupyter Notebook

 Open terminal/command prompt and type:

 jupyter notebook

 It will open a web-based interface in your browser (default: http://localhost:8888).

🔹 Basic Components

 Notebook → A file with extension .ipynb.

 Cell → Two main types:

o Code Cell → For Python code execution.

o Markdown Cell → For text, headings, equations.

Example:

# Code Cell

x=5

y = 10

print(x + y)

Output:

15

Markdown example:

# Heading 1

## Heading 2

**Bold Text** and *Italic Text*

Python Data Types

In Python, every value (variable, constant, expression) has a data type that defines what kind of
value it is and what operations can be performed on it.

Python has built-in (standard) data types, which can be grouped as follows:
🔹 1. Numeric Types

 int → Integer numbers (positive, negative, zero).

 a = 10 # int

 b = -45

 float → Decimal numbers (real numbers).

 pi = 3.14 # float

 complex → Complex numbers (a + bj).

 z = 2 + 3j # complex number

🔹 2. Sequence Types

 str (String) → Text data inside quotes (' ', " ", or ''' ''').

 name = "Python"

 list → Ordered, mutable collection of items.

 fruits = ["apple", "banana", "cherry"]

 tuple → Ordered, immutable collection.

 point = (10, 20)

 range → Sequence of numbers (used in loops).

 nums = range(5) # 0,1,2,3,4

🔹 3. Set Types

 set → Unordered, mutable collection with unique elements.

 s = {1, 2, 3, 3, 2} # {1, 2, 3}

 frozenset → Immutable version of a set.

 fs = frozenset([1, 2, 3])
🔹 4. Mapping Type

 dict (Dictionary) → Key–Value pairs.

 student = {"name": "Sharanya", "age": 25, "course": "Python"}

🔹 5. Boolean Type

 bool → Represents True or False.

 is_adult = True

 is_child = False

🔹 6. Binary Types

 bytes → Immutable sequence of bytes.

 b = b"Hello"

 bytearray → Mutable sequence of bytes.

 ba = bytearray([65, 66, 67])

 memoryview → Memory view object for accessing memory of other binary objects.

 mv = memoryview(b"Python")

🔹 Type Conversion

Python allows conversion between data types using type casting:

x = 10

print(float(x)) # int → float (10.0)

y = "123"

print(int(y)) # str → int (123)

z = list("abc")
print(z) # str → list ['a', 'b', 'c']

🔹 Checking Data Type

Use type() function:

print(type(10)) # <class 'int'>

print(type(3.14)) # <class 'float'>

print(type("Python")) # <class 'str'>

print(type([1,2,3])) # <class 'list'>

You might also like