[Link] IS PYTHON?
Python is a very popular general-purpose interpreted,
interactive, object-oriented, and high-level programming
language. Python is dynamically-typed and garbage-collected
programming language.
Python was conceived in the late 1980s by Guido van
Rossum at the National Research Institute for Mathematics and
Computer Science (CWI) in the Netherlands
[Link] EXTENSION COMPARISON:
Extensio
Type Purpose Platform
n
Human-
Source
.py readable All
Code
Python code
Compiled
.pyc Bytecode Python for All
faster loading
Deprecated
Optimized All
.pyo optimized
Bytecode (deprecated)
compilation
Compiled
Extension
.pyd extension Windows
Module
(like .dll)
[Link] WORKING OF PYTHON
Python doesn't convert its code into machine code,
something that hardware can understand. It converts it into
something called byte code. So within Python, compilation
happens, but it's just not in a machine language. It is into byte
code (.pyc or .pyo) and this byte code can't be understood by the
CPU. So we need an interpreter called the Python virtual machine
to execute the byte codes.
[Link] OF PYTHON
Characterist
What it means
ic
Readability Focus on clean code using indentation.
Free & Open Anyone can download it and contribute to its
Source source code.
GUI Support Can be used to develop desktop applications.
You can perform complex tasks with just a few
Expressive
lines of code.
[Link] OF PYTHON:
Python in Real World
Popular
Field Why Python?
Example
Social Media Instagram Scalable and clean code.
Recommendation algorithms
Entertainment Netflix
(AI).
Fast development and web
Search Engine Google
crawling.
Popular
Field Why Python?
Example
Space
NASA Data analysis and simulations.
Research
[Link] OF PYTHON:
Simple & Readable Syntax: Python uses a clean, English-like
syntax that is intuitive for beginners. It replaces complex
punctuation like curly braces with significant indentation to
define code blocks.
Interpreted Nature: Python code is executed line-by-line by an
interpreter rather than being compiled entirely before execution.
This allows for rapid testing and easier debugging.
Dynamically Typed: You do not need to declare variable types
(e.g., int or string) manually; the interpreter determines the type
at runtime based on the assigned value.
Free and Open Source: The language is developed under
an OSI-approved open-source license, making it free to download,
use, and modify for both personal and commercial projects.
Cross-Platform Compatibility: Python is platform-independent;
code written on one operating system (Windows, macOS, Linux)
can run on another without modification via the Python Virtual
Machine.
Multi-Paradigm Support: It supports various programming
styles, including Object-Oriented Programming
(OOP), Procedural, and Functional programming.
Python's most important features are as follows:
Easy to Learn
Dynamically Typed
Interpreter Based
Interactive
Multi-paradigm
Standard Library
Open Source and Cross Platform
GUI Applications
Database Connectivity
Extensible
Active Developer Community
[Link] BETWEEN PYTHON AND C++
The following table summarizes the differences between Python and C++
Criteria Python C++
Python is an interpreted-based C++ is a compiler-based
programming language. Python programming language. C++
Execution
programs are interpreted by an programs are compiled by a
interpreter. compiler.
Python is a dynamic-typed
Typing C++ is a static-typed language.
language.
C++ is not a portable language,
Python is a highly portable
code written and executed on a
language, code written and
Portability system cannot be run on
executed on a system can be
another system without making
easily run on another system.
changes.
Python provides a garbage
C++ does not provide garbage
collection feature. You do not
Garbage collection. You have to take
need to worry about the
collection care of freeing memories. It is
memory management. It is
manual in C++.
automatic in Python.
Python's syntaxes are very easy
Syntax C++'s syntaxes are tedious.
to read, write, and understand.
Python's execution performance C++ codes are faster than
Performance
is slower than C++'s. Python codes.
Python's application areas are C++'s application areas are
Application
machine learning, web embedded systems, device
areas
applications, and more. drivers, and more.
[Link] DATA TYPES:
Data types in Python are a way to classify data items. They represent the
kind of value which determines what operations can be performed on that
data. Since everything is an object in Python programming, Python data
types are classes and variables are instances (objects) of these classes.
The following are standard or built-in data types in Python:
Numeric: int, float, complex
Sequence Type: string, list, tuple
Mapping Type: dict
Boolean: bool
Set Type: set, frozenset
Binary Types: bytes, bytearray, memoryview
x = 50 # int
x = 60.5 # float
x = "Hello World" # string
x = ["hello", "for", "hai"] # list
x = ("hello", "for", "hai") # tuple
Numeric Data Types
Output
a=5
<class 'int'>
print(type(a))
<class 'float'>
b = 5.0 <class 'complex'>
print(type(b))
c = 2 + 4j
print(type(c))
Sequence Data Types
String Data Type:
Python Strings are arrays of bytes representing Unicode characters. In Python, there is no character data type, a character is a
string of length one. It is represented by str class.
s = 'Welcome to Dvh computer' Welcome to Dvh computer
print(s) <class 'str'>
e
l
r
# check data type
print(type(s))
# access string with index
print(s[1])
print(s[2])
print(s[-1])
# -1 refers to the last character, -2 is second last, and so on
print(“hi”)
List Data Type
# Empty list [1, 2, 3]
a = [] ['DVH', 'For', 'DVH',
4, 5]
# list with int values
a = [1, 2, 3]
print(a)
# list with mixed values int and String
b = ["DVH", "For", "DVH", 4, 5]
print(b)
Tuple Data Type
Tuple is an ordered collection of Python objects. The only difference between a tuple and a list is that tuples are immutable. Tuples
cannot be modified after it is created.
# initiate empty tuple
tup1 = ()
tup2 = ('hello', 'For')
print("\nTuple with the use of String: ", tup2)
Feature List Tuple
Mutability Mutable: Elements can be added, Immutable: Cannot be modified after
removed, or modified. creation.
Syntax Defined with square brackets: [1, 2, Defined with parentheses: (1, 2,
3]. 3).
Memory Higher: Requires extra memory for Lower: More memory-efficient due to
Usage dynamic resizing. fixed size.
Performance Slower: Modifying elements requires Faster: Better performance for
more overhead. iteration and access.
Methods Many built-in methods Few built-in methods (count, index).
(append, remove, sort).
Dictionary Cannot be used as a dictionary key. Can be used as a dictionary key (if
Key elements are hashable).
OPERATORS: