KEMBAR78
Basics of python programming | PDF
Basics of Python
Programming
-By Aditi Bhushan
Aditi Bhushan 1
UNIT – 2: PYTHON [REVISED SYLLABUS]
• TOTAL = 25/100
• Basics of Python programming,
• Python interpreter - interactive and script
mode,
• the structure of a program,
• indentation,
• identifiers, keywords, constants, variables,
• types of operators, precedence of operators,
• data types, mutable and immutable data
types,
• statements, expressions, evaluation and
comments, input and output statements
• data type conversion,
• debugging.
• Control Statements: if-else, for loop
• Lists: list operations - creating,
initializing, traversing and
manipulating lists, list methods and
built-in functions.
• Dictionary: concept of key-value pair,
creating, initializing, traversing,
updating and deleting elements,
dictionary methods and built-in
functions.
Aditi Bhushan 2
Introduction to Python
Version Python 3 or Python 3.7.0 or Latest Version: Python 3.8.5
Aditi Bhushan 3
Why Python? (for understanding purpose, not
for evaluation)
• Powerful Language
• Supports “Scripting Language”
• Concise Formatting Style of Language
• Every Value is an Object.
• Supports iteration and abstractions – thereby making
generics easy with dynamic typing
Aditi Bhushan 4
Language Features (for understanding
purpose, not for evaluation)
• Supports Indentation instead of braces
• Powerful subscripting (slicing)
• Functions are independent entities (not all functions are methods)
• Exceptions as in Java
• Simple object system
• Iterators (like Java) and generators
• Several sequence types
• Strings ’…’: made of characters, immutable
• Lists […]: made of anything, mutable
• Tuples (…) : made of anything, immutable
Aditi Bhushan 5
Basics of Python
• Created by Guido van Rossum in 1991
• Object Oriented Programming
• Uses: software development, web development, scientific computing,
big data and artificial intelligence
• Download Latest Version of Python IDE from:
https://www.python.org/
• Online Editor for Python:
https://www.onlinegdb.com/online_python_compiler
Aditi Bhushan 6
Installation
• Python is pre-installed on most Unix systems,
including Linux and MAC OS X
• Python comes with a large library of standard modules
• There are several options for an IDE
• IDLE – works well with Windows
• Emacs with python-mode or your favorite text editor
• Eclipse with PyDev (http://pydev.sourceforge.net/ )
• PyCharm (https://www.jetbrains.com/pycharm/)
Aditi Bhushan 7
Starting with Python
Installation Steps (Please Find attached the Pics)
1. Put a tick mark on Add Path
Aditi Bhushan 8
2. Change Custom Path (Optional)
Aditi Bhushan 9
IDLE Development Environment
• IDLE is an Integrated DeveLopment Environment for Python, typically
used on Windows
• Multi-window text editor with
• syntax highlighting,
• auto-completion,
• smart indention
• Integrated debugger with
• stepping,
• persistent breakpoints,
• call stack visibility
Aditi Bhushan 10
Windows IDLE
Aditi Bhushan 11
To write and run (execute) a Python program, we need to have a
✓ Python interpreter installed on our computer or
✓ any online Python interpreter. The interpreter is also called Python shell.
Python Interpreter
Here, the symbol >>> is called Python prompt, which indicates that the
interpreter is ready to receive instructions.
Execution Modes
INTERACTIVE MODE
• Single line code for instant
execution.
• Good for beginners at starting.
• We cannot save the statements for
further use.
SCRIPT MODE
• Python Program/Scripts are written
and saved with .py extension.
• Good for bigger programs or
professionals.
• We can Save and Reuse them.
Consist of built-in editors known as
IDLE.
• By default, the Python scripts are
saved in the Python installation
folder.
Aditi Bhushan 12
COMMENTS
• Start comments with #, rest of line is ignored
• Can include “string” as the first line of a new function.
• Development environments, debugger, and other tools use it: it’s
good style to include one
def fact(n):
“““fact(n) assumes n is a positive integer and
returns factorial of n.”””
assert(n>0)
return 1 if n==1 else n*fact(n-1)
Aditi Bhushan 13

Basics of python programming

  • 1.
    Basics of Python Programming -ByAditi Bhushan Aditi Bhushan 1
  • 2.
    UNIT – 2:PYTHON [REVISED SYLLABUS] • TOTAL = 25/100 • Basics of Python programming, • Python interpreter - interactive and script mode, • the structure of a program, • indentation, • identifiers, keywords, constants, variables, • types of operators, precedence of operators, • data types, mutable and immutable data types, • statements, expressions, evaluation and comments, input and output statements • data type conversion, • debugging. • Control Statements: if-else, for loop • Lists: list operations - creating, initializing, traversing and manipulating lists, list methods and built-in functions. • Dictionary: concept of key-value pair, creating, initializing, traversing, updating and deleting elements, dictionary methods and built-in functions. Aditi Bhushan 2
  • 3.
    Introduction to Python VersionPython 3 or Python 3.7.0 or Latest Version: Python 3.8.5 Aditi Bhushan 3
  • 4.
    Why Python? (forunderstanding purpose, not for evaluation) • Powerful Language • Supports “Scripting Language” • Concise Formatting Style of Language • Every Value is an Object. • Supports iteration and abstractions – thereby making generics easy with dynamic typing Aditi Bhushan 4
  • 5.
    Language Features (forunderstanding purpose, not for evaluation) • Supports Indentation instead of braces • Powerful subscripting (slicing) • Functions are independent entities (not all functions are methods) • Exceptions as in Java • Simple object system • Iterators (like Java) and generators • Several sequence types • Strings ’…’: made of characters, immutable • Lists […]: made of anything, mutable • Tuples (…) : made of anything, immutable Aditi Bhushan 5
  • 6.
    Basics of Python •Created by Guido van Rossum in 1991 • Object Oriented Programming • Uses: software development, web development, scientific computing, big data and artificial intelligence • Download Latest Version of Python IDE from: https://www.python.org/ • Online Editor for Python: https://www.onlinegdb.com/online_python_compiler Aditi Bhushan 6
  • 7.
    Installation • Python ispre-installed on most Unix systems, including Linux and MAC OS X • Python comes with a large library of standard modules • There are several options for an IDE • IDLE – works well with Windows • Emacs with python-mode or your favorite text editor • Eclipse with PyDev (http://pydev.sourceforge.net/ ) • PyCharm (https://www.jetbrains.com/pycharm/) Aditi Bhushan 7
  • 8.
    Starting with Python InstallationSteps (Please Find attached the Pics) 1. Put a tick mark on Add Path Aditi Bhushan 8
  • 9.
    2. Change CustomPath (Optional) Aditi Bhushan 9
  • 10.
    IDLE Development Environment •IDLE is an Integrated DeveLopment Environment for Python, typically used on Windows • Multi-window text editor with • syntax highlighting, • auto-completion, • smart indention • Integrated debugger with • stepping, • persistent breakpoints, • call stack visibility Aditi Bhushan 10
  • 11.
    Windows IDLE Aditi Bhushan11 To write and run (execute) a Python program, we need to have a ✓ Python interpreter installed on our computer or ✓ any online Python interpreter. The interpreter is also called Python shell. Python Interpreter Here, the symbol >>> is called Python prompt, which indicates that the interpreter is ready to receive instructions.
  • 12.
    Execution Modes INTERACTIVE MODE •Single line code for instant execution. • Good for beginners at starting. • We cannot save the statements for further use. SCRIPT MODE • Python Program/Scripts are written and saved with .py extension. • Good for bigger programs or professionals. • We can Save and Reuse them. Consist of built-in editors known as IDLE. • By default, the Python scripts are saved in the Python installation folder. Aditi Bhushan 12
  • 13.
    COMMENTS • Start commentswith #, rest of line is ignored • Can include “string” as the first line of a new function. • Development environments, debugger, and other tools use it: it’s good style to include one def fact(n): “““fact(n) assumes n is a positive integer and returns factorial of n.””” assert(n>0) return 1 if n==1 else n*fact(n-1) Aditi Bhushan 13