0% found this document useful (0 votes)
14 views

FPP_UNIT1

The document provides an introduction to Python programming, covering its installation, basic syntax, and key concepts such as identifiers, reserved words, and indentation. It outlines the history and features of Python, its applications in various fields, and the differences between interactive and script mode programming. Additionally, it discusses standard data types, operators, control statements, and the functioning of the Python interpreter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

FPP_UNIT1

The document provides an introduction to Python programming, covering its installation, basic syntax, and key concepts such as identifiers, reserved words, and indentation. It outlines the history and features of Python, its applications in various fields, and the differences between interactive and script mode programming. Additionally, it discusses standard data types, operators, control statements, and the functioning of the Python interpreter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Fundamentals of Python

Programming

- By Binodini Kar
Unit 1 : Introduction

Installation, First python program: Interactive


Mode Programming, Script Mode Programming;
Identifiers, Reserved words, Lines and
Indentation, Multi-line Statements, Quotation &
comments; Assigning values to variables, Multiple
Assignment.
Introduction

• What is Python ?
• History of Python
• Features of Python
• Why Python?
• Companies that uses python
What is Python?
• Python is an interpreted, object oriented, high-level programming
language with dynamic semantics.
-- python syntax are easy compared to other languages.

Let’s understand above definition more clearly.

Interpreted – Interpreted programming languages uses interpreter for it’s


translation.
--- Interpreter – it is a software program written to translate source code
to machine code but it does that line by line.

(compiler and interpreter are translators, they are used to translate the
code written in one language to the code written in another.)
• High-level Programming language – This means that we humans can
understand this language without any problem.
Eg : - length = 20
breadth = 40
area = length * breadth
print(area)

Eg : - 111010
011111
(low level programming)

Easy syntax
Dynamic semantics
History of Python

• Python was introduced by Guido Van Rossum in 1989.


• First version of python released in 1991.
• In 1994, python 1.0 was released with new feature
which includes map, filter, lambda.
• Python 2.x also add some more features like
comprehension, garbage collection system.
• He named this language python because he is a big fan
of a British comedy series “Monty python’s flying
circus”.
Features of python :-
• Easy syntax( Easy to learn and implement)
• Open source
• Broad standard library
• Cross platform
• Multi- paradigm language(It supports object oriented
programming and functional/structural programming.)
• High level programming
• GUI programming support
Why Python?
• Data Analysis
• Robotics
• Website and Application development
• Desktop application
• Games Development
• Web scraping
• Data visualization
• ML & AI (Machine learning & Artificial Intelligence)
• Audio & video software development (VLC player)
Some Companies that uses python :
-
Interactive Mode and Script Mode
Programming :
Interactive mode and script mode are two different ways of running
Python code.

• Interactive mode allows you to enter Python commands directly into


the Python shell, and the interpreter executes them immediately.
• You can open the Python shell by typing python or python3 in your
terminal or command prompt.
• In interactive mode, you can enter Python statements one at a time,
and the interpreter executes them immediately and shows the result.
• It's useful for testing small code snippets, experimenting with Python
features, or running quick calculations.
• Script mode involves writing your Python code in a
separate file (a text file with a .py extension) and then
running the entire file using the Python interpreter.
• You can create a Python script using any text editor or
integrated development environment (IDE).
• Once you've written the code in a file, you run it by
passing the filename to the Python interpreter as a
command-line argument.
• Script mode is typically used for larger programs or
projects where you want to organize your code into
separate files and execute them as needed.
The file
test.py
(lines of
code
written in
a text
editor(Not
epad))
• Identifiers
• Reserved words
• Lines and Indentation
• Multi line statements
• Quotations
• Comments
Identifiers
• A name in python program is called Identifier.
It can be a class name, function name, module name or a
variable name.
Eg : a = 10;

Rules to define Identifiers in python : -


 The only allowed character in python are :
--alphabets (either lower or upper case)
--digits (0-9)
--underscore symbol (_)
 Identifier should not start with a digit.
12num num12
 Identifiers are case sensitive (Python language is case sensitive.).
Num and num are treated differently.
 Reserved words cannot be used as an Identifier.
class = ‘BCA’ Class = ‘BCA’
 No whitespace character should be present in between the
different words in a single identifier.
area of rectangle area_of_rectangle
 There is no length limit for python identifiers. But it’s not
recommended to use too lengthy identifier.
natural_numbers natural_num
Reserved words (keywords)

• In python some words are reserved to represent some


special meaning or functionality. Such type of words
are called reserved words.
• They can’t be used for variable name, function name,
or any other identifiers.
• There are total of 35 keywords in python.
import keyword
keyword.kwlist
Value keywords : True, False, None
Operator keywords : and, or ,not ,is ,in
Iteration Keywords: for, while, break, continue
Conditional Keywords: if, else, elif
Structure Keywords: def, class, pass, lambda
Returning Keywords: return, yield
Import Keywords: import, from, as
Exception-Handling Keywords: try, except, raise, finally, assert, with
Asynchronous Keywords: async, await
Variable Handling Keywords: del, global, non-local
Lines and Indentation
• A line in python is a single instruction or statement.
• Statement typically ends with a newline character.
Newline termination : - The most common way to end a
statement in Python is by placing it on a new line. When
the Python interpreter encounters a newline character,
it interprets it as the end of the current statement.
Implicit line continuation : - Python allows implicit line
continuation within parentheses, brackets, and curly
braces. If an expression is enclosed within these
grouping symbols, python automatically considers the
expression as continuing to the next line, allowing us to
break long lines of code for better readability.
• Explicit Line Continuation: You can explicitly continue
a statement to the next line using the backslash (\)
character. This indicates to the Python interpreter that
the statement continues on the next line.
Indentation
• It refers to the spaces or tabs at the beginning of a line. It
helps python understand the structure of any code.
• By indenting, we group lines of code together to form
blocks or sections.
Eg : -
if x > 5:
print(“x is greater than 5.”)
The above lines of code under the if statement are indented.
It tells python that these lines are part of the condition and
should only be executed if the condition is true.
• Indent is the space that we normally leave from the left
margin of our document.
• Uniformly indented block starts after ‘:’ (colon).
• Number of spaces is variable(changeable), but all the
statements within the block must have same indent.
• Sequence of statements having same level of indent
forms a block.
Quotations and comments

• Python accepts single(‘), double(“) and triple(“ “ “, ‘ ‘ ‘)


quotes to denote string literals, as long as the same
type of quote starts and ends the string.
• The triple quotes are used to span the string across
multiple lines.

• Comments are used to add explanations or annotations


to the code, which are ignored by the interpreter during
execution.
• They are helpful for making the code more
understandable to other developers(including your
• Single line comment
#This is a single line comment.

Multi-line comment
“ “ “This is a multiline comment
It spans multiple lines.” ” ”
Unit 2 : Standard Data types

Numbers, Strings, Lists, Tuples, Dictionary; Data Type


Conversion; Basic Operators: Arithmetic, Comparison,
Assignment, Bitwise; Operators: Logical, Membership,
Identity; Operators Precedence; Python Numbers &
Mathematical functions. Data Type Conversion: Basic
Operators: Arithmetic, Comparison, Assignment, Bitwise;
Basic Operators, Python Numbers & Mathematical
functions; Python Strings.
Unit 3 : Python statements and Loops

if, if-else, While, for loops, break, continue, pass,


Python Function; Files I/O.
Functions: Definition, call, positional and
keyword parameter. Default parameters, variable
number of arguments. Modules - import
mechanisms. Functional programming - map,
filter, reduce, max, min. lambda function - list
comprehension
• How does machine understand the interpreted code if it does not
create any executable file?
• In Python, the interpreter translates the high-level Python code into machine-readable bytecode. This bytecode is then
executed by the Python Virtual Machine (PVM), which is essentially a runtime environment for Python code. So, while
Python itself doesn't generate traditional executable files like compiled languages do, it produces bytecode that the PVM
can execute directly. This process allows Python to be platform-independent since the bytecode can run on any system
with a compatible Python interpreter installed.

• How does python interpreter knows about the end of a statement in


python?
In Python, the end of a statement is typically indicated by a newline character ( \n). This means that Python relies on
the newline character to determine the end of a statement. However, Python is also designed to be flexible in terms
of formatting, allowing statements to span multiple lines using explicit line continuation mechanisms like backslashes
(\) or enclosing expressions in parentheses, braces, or brackets without the need for explicit line continuation
characters.

You might also like