0% found this document useful (0 votes)
20 views45 pages

Python Programming Basics and Concepts

The document provides an overview of programming languages, focusing on high-level languages like Python, Java, and JavaScript, as well as low-level languages such as Assembly and Machine Code. It explains common programming concepts including syntax, variables, data types, functions, and control flow, along with an introduction to Python programming and its installation. Additionally, it covers error types, the importance of problem-solving in programming, and the structure of a program.

Uploaded by

Soujay Ghoshal
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)
20 views45 pages

Python Programming Basics and Concepts

The document provides an overview of programming languages, focusing on high-level languages like Python, Java, and JavaScript, as well as low-level languages such as Assembly and Machine Code. It explains common programming concepts including syntax, variables, data types, functions, and control flow, along with an introduction to Python programming and its installation. Additionally, it covers error types, the importance of problem-solving in programming, and the structure of a program.

Uploaded by

Soujay Ghoshal
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

23CSE109

Python Programming
Programming languages
Tools used by developers to write instructions that a computer can
understand and execute.
Create software to solve problems and perform specific tasks.

Types:
[Link] Level Programming languages
[Link] Level Programming languages
High Level Programming Languages
•Python: Known for its simplicity and readability. Used in web development,
data analysis, artificial intelligence, and more.

•Java: Widely used in enterprise environments, Android app development,


and web applications.

•C++: An extension of C, used for system/software development, game


development, and performance-critical applications.

•JavaScript: The language of the web. Used for front-end development,


server-side development ([Link]), and more.
Low-Level Languages:
•Assembly: A low-level language that is specific to a computer architecture.
Used for writing performance-critical and hardware-specific code.
•Human readable.

•Machine Code: The lowest level of code directly executed by the CPU.
Written in binary and hexadecimal.
•Not human readable
Common Programming Terms
Syntax: The set of rules that define the combinations of symbols considered to
be correctly structured programs in a language.

•Example: In Python, the syntax for a print statement is print("Hello, World!").

Variable: A storage location paired with a name, which contains data that can
be modified during program execution.

•Example: x = 10
Common Programming Terms
Data Type: A classification that specifies which type of value a variable can hold.

•Common data types: integers, floats, strings, booleans.

Function: A block of code designed to perform a particular task, which can be


reused.

Control Flow: The order in which individual statements, instructions, or


function calls are executed or evaluated.

•Includes conditionals (if, else, elif), loops (for, while).


Common Programming Terms
• Loop: A sequence of instructions that repeats until a certain
condition is met.
• loops (for, while).

• Conditional Statement: A statement that performs different actions based on


whether a boolean condition evaluates to True or False.

• conditionals (if, else, elif),


• Array/List: A collection of elements, typically of the same data type, stored
in a specific order.

• Example: numbers = [1, 2, 3, 4, 5]


Dictionary: A collection of key-value pairs, where each key is unique.

Name(Key): Karthi(Value)
Roll No. (Key): 32(Value)

Module/Library: A file containing Python definitions and statements


intended for use in other Python programs.
Module Description Example Use Case
Performing mathematical operations
math Provides mathematical functions
like sqrt, sin, cos
pandas Provides data structures and data analysis tools Data manipulation and analysis
Provides support for large multi-dimensional arrays Numerical computations and linear
numpy
and matrices algebra
A plotting library for creating static, animated, and
matplotlib Data visualization and plotting graphs
interactive visualizations
Provides modules for scientific and technical Scientific computations, optimization,
scipy
computing and signal processing
Provides simple and efficient tools for data mining and
scikit-learn Machine learning and data mining
data analysis
An open-source library for machine learning and deep Developing and training machine
tensorflow
learning learning models
flask A micro web framework for Python Creating web applications and APIs

django A high-level Python web framework Building complex web applications


Creating graphical user interfaces
tkinter The standard Python interface to the Tk GUI toolkit
(GUIs)
A set of Python modules designed for writing video
pygame Game development
games
Compilation vs. Interpretation:
• Compiled Languages: Languages like C and C++ are compiled, meaning
the source code is translated into machine code by a compiler before
execution.
• A compiler is defined as a software that transforms an entire set of source
code into object code and saves it as a file before executing it.
• Interpreted Languages: Languages like Python and JavaScript are
interpreted, meaning the source code is executed line-by-line by an
interpreter.
Interpreter and Compiler
•Algorithm: A step-by-step procedure or formula for solving a problem.
•Example: An algorithm to sort an array of numbers.

•Debugging: The process of finding and fixing errors in the code.


PYTHON
Python Programming Language
• A high-level, interpreted programming language.
• Emphasizes code readability with its use of significant indentation.
• Widely used in web development, data analysis, artificial intelligence,
scientific computing, and more.
• Easy to learn for beginners and has a wide range of applications.
Step-by-Step Installation

• 1. Download and Install Python


• For Windows:
[Link] to the Python official website.
[Link] on the "Download Python" button for the latest version.
[Link] the downloaded installer.
[Link] installation, make sure to check the box that says "Add
Python to PATH."
[Link] on "Install Now."
2. Jupyter Notebook
• Download “ Anaconda” .exe file
• Install it
• Launch Jupyter Notebook.
Popular Python IDEs
Here are some popular IDEs used for Python development:
IDE Description
A powerful IDE developed by JetBrains, tailored
PyCharm
specifically for Python development.
A lightweight but powerful source code editor with
Visual Studio Code
support for many languages, including Python.
An open-source web application that allows you to
Jupyter Notebook
create and share documents containing live code.
An open-source IDE designed for scientific
Spyder
programming in Python.
Books Referred
How to Think Like a Computer Scientist
Learning with Python

Allen Downey
Jeffrey Elkner
Chris Meyers
The Way of Program
• The goal of this course is to teach you to think like a computer
scientist.
• This way of thinking combines some of the best features of
mathematics, engineering, and natural science.
• Like mathematicians, computer scientists use formal languages
to denote ideas (specifically computations).
• Like engineers, they design things, assembling components into
systems and evaluating tradeoffs among alternatives.
• Like scientists, they observe the behavior of complex systems,
form hypotheses, and test predictions.
The Way of Program
• The single most important skill for a computer scientist is problem
solving.
• Problem solving means the ability to formulate problems, think
creatively about solutions, and express a solution clearly and
accurately.
• As it turns out, the process of learning to program is an excellent
opportunity to practice problem solving skills.
What is Program?
• A program is a sequence of instructions that specifies how to
perform a computation.
• The computation might be something mathematical, such as
solving a system of equations or finding the roots of a polynomial,
but it can also be a symbolic computation, such as searching and
replacing text in a document
Error Message
Syntax errors:
• Python can only execute a program if the program is syntactically
correct; otherwise, the process fails and returns an error message.
• Syntax refers to the structure of a program and the rules about that
structure.
Runtime errors:
• The second type of error is a runtime error, so called because the error
does not appear until you run the program.
• These errors are also called exceptions because they usually indicate
that something exceptional (and bad) has happened
Error Message
Semantic errors:
The third type of error is the semantic error. If there is a semantic
error in your program, it will run successfully, in the sense that the
computer will not generate any error messages, but it will not do
the right thing. It will do something else.
The meaning of the program (its semantics) is wrong. Identifying
semantic errors can be tricky because it requires you to work
backward by looking at the output of the program and trying to
figure out what it is doing.
The first program
• Traditionally, the first program written in a new language is called
“Hello, World!” because all it does is display the words, “Hello,
World!”
• In Python, it looks like this:

print("Hello, World!")
Values
Values are
• 2 – integer
• 3.5 – float
• “ Hello World” – String
• To know the type of value
• type(2) -int
• type(3.5) - float
• type(“Hello World”)-string
Variables
• A variable is a name that refers to a value.
• The assignment statement creates new variables and gives them values:
• message = "What’s up, Doc?"
• n = 17
• pi = 3.14159
• This example makes three assignments.
• The first assigns the string "What’s up, Doc?" to a new variable named
message.
• The second gives the integer 17 to n, and the
• third gives the floating-point number 3.14159 to pi.
• print(message)
• print(n)
• print(pi)
Variables
• Output:
• What’s up, Doc?
• 17
• 3.14159

• Result is the value of the variable.


• Variables also have types; again, we can ask the interpreter what they
are
• type(n)
• int
Variable Name
• Both letter and number
• Starts with letter
• Bruce and bruce are different
• Use underscore for long variables
Python Keywords
• Python Keywords define the language’s rules and structure, and
they cannot be used as variable names.
• Python has twenty-nine keywords:
Statement
• A statement is an instruction that the Python interpreter can
execute.
• We have seen two kinds of statements: print and assignment.
• The result of a print statement is a value. Assignment statements
don’t produce a result
Evaluating expressions
• An expression is a combination of values, variables, and
operators. If you type an expression on the command line, the
interpreter evaluates it and displays the result:
x=2
y = x(variable) +(operator) 2(value)
Print(y)

• Output: 4
Operators and operands
• Operators are special symbols that represent computations like
addition and multiplication.
• The values the operator uses are called operands.
Order of operations
• When more than one operator appears in an expression, the order
of evaluation depends on the rules of precedence.
• Python follows the same precedence rules for its mathematical
operators that mathematics does.
• The acronym PEMDAS is a useful way to remember the order of
operations
• Parentheses, Exponentiation, Multiplication, Division, Addition
and Subtraction
• (1+1)**(5-2) is 8; 2 * (3-1) is 4; 2**1+1 is 3 and not 4; 3*1**3 is 3
and not 27

You might also like