1 of 25

Introduction to Python Programming

Getting Started with Python: Concepts, Syntax, and Execution

Presented by:�Mr. Atul Kalukhe

2 of 25

Introduction to Python

  • What is Python?� Python is a high-level, interpreted, general-purpose programming language. It is known for its simple syntax that mimics natural language, making it easy to read and write.�
  • Who Created Python?� Python was developed by Guido van Rossum in the late 1980s and was first released in 1991.�
  • Key Features of Python:�
    • Simple and Easy to Learn: Python has a clean and readable syntax.�
    • Interpreted Language: Code is executed line-by-line without compiling.�
    • High-Level Language: Closer to human language than machine language.�
    • Portable: Python code can run on different platforms with little or no modification.�
    • Extensive Library Support: Comes with a large standard library and thousands of external modules.

3 of 25

History of Python Programming

  • Late 1980s – Origin:�
    • Python was developed as a hobby project by Guido van Rossum during his Christmas holidays in 1989.�
    • It was meant to be a successor to the ABC programming language with better exception handling and extensibility.�
  • 1991 – First Release:�
    • Python 0.9.0 was released in February 1991.�
    • Included features: classes, functions, exception handling, and core data types like list, dict, str.�
  • 2000 – Python 2.0:�
    • Introduced list comprehensions, garbage collection using reference counting, and Unicode support.�
  • 2008 – Python 3.0:�
    • Also known as “Python 3000” or “Py3k”.�
    • Major revision; not backward compatible with Python 2.x.�
    • Improved handling of strings, division, and syntax changes for consistency.�

4 of 25

  • Recent Updates:�
    • Python continues to evolve with regular updates and enhancements.�
    • Latest versions (Python 3.x) add performance improvements and advanced modules (e.g., async, dataclasses).�
  • Python Today:�
    • One of the most popular and widely used programming languages in the world.�
    • Used in education, industry, research, and technology.

5 of 25

Why Do We Need Python Programming?

  • 1. Easy to Learn and Use�
    • Python has a clean and straightforward syntax similar to English.�
    • Minimal lines of code needed to perform complex tasks.�
  • 2. Versatile and Powerful�
    • Supports multiple programming paradigms: procedural, object-oriented, and functional.�
    • Can be used in various domains like web development, data analysis, automation, etc.�
  • 3. Rapid Application Development�
    • Ideal for building prototypes and production-level applications quickly.�
    • Availability of frameworks and libraries speeds up development.�
  • 4. Strong Community Support�
    • One of the largest programming communities.�
    • Rich documentation and countless tutorials, forums, and tools.�

6 of 25

  • 5. Cross-platform Compatibility�
    • Python is platform-independent – the same code runs on Windows, Mac, and Linux with minimal changes.�
  • 6. Extensive Libraries and Frameworks�
    • Includes built-in modules and external packages like:�
      • NumPy, Pandas – for data analysis�
      • Django, Flask – for web development�
      • TensorFlow, PyTorch – for AI/ML�
      • Tkinter – for GUI apps�
  • 7. In-demand Skill�
    • Python developers are highly sought after in industries like tech, finance, education, healthcare, and more.

7 of 25

Real-World Applications of Python

  • 1. Web Development�
    • Frameworks like Django, Flask, and FastAPI simplify backend development.�
    • Used for building secure, scalable, and maintainable web applications.�
  • 2. Data Science and Machine Learning�
    • Libraries such as NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, and PyTorch are widely used.�
    • Used for data analysis, visualization, predictive modeling, and AI.�
  • 3. Automation and Scripting�
    • Python is ideal for writing scripts to automate repetitive tasks, such as file handling, web scraping, and system maintenance.�
  • 4. Game Development�
    • Libraries like Pygame allow developers to create simple 2D games.�
    • Used for rapid prototyping of game logic and AI.�
  • 5. Desktop GUI Applications�
    • Toolkits like Tkinter, PyQt, and Kivy help create cross-platform graphical user interfaces.�

8 of 25

  • 6. Internet of Things (IoT)�
    • Python is used with devices like Raspberry Pi to develop smart gadgets and IoT prototypes.�
  • 7. Cybersecurity and Ethical Hacking�
    • Python scripts are used for penetration testing, network scanning, and writing custom exploits.�
  • 8. Education and Research�
    • Python is a first choice in schools, colleges, and online platforms due to its simplicity and readability.�
    • Used in academic research across science, mathematics, and engineering fields.

9 of 25

Fundamentals of Python Programming

  • High-Level Language:� Python is designed to be easily readable and writable, allowing developers to focus more on problem-solving than syntax.�
  • Interpreted Language:� Python does not need to be compiled. It runs line-by-line using an interpreter, making it easier to test and debug code.�

Dynamically Typed:� Variables do not require explicit type declaration. The data type is inferred during runtime.��x = 10 # Integer

x = "Hi" # Now a string

  • Object-Oriented and Procedural Support:�
    • Python supports object-oriented programming (OOP) concepts like classes and objects.�
    • Also supports procedural programming through functions and modules.�

10 of 25

  • Readable Syntax:�
    • Python code closely resembles English.�
    • Indentation is mandatory to define blocks of code, which improves readability.�
  • Portable and Cross-platform:� Python programs can run on multiple platforms (Windows, Mac, Linux) without modification.�
  • Vast Standard Library:� Comes with modules for math, file I/O, system functions, internet protocols, and more.�

Code Example:

print("Welcome to Python Programming!")

11 of 25

Using the Python REPL (Interactive Shell)

  • What is REPL?� REPL stands for:� R – Read, E – Evaluate, P – Print, L – Loop� It is an interactive environment that reads user input, evaluates it, prints the result, and waits for the next command.�
  • How to Access REPL:�
    • Open command prompt or terminal�
    • Type python or python3 and press Enter�
    • You will see the Python prompt >>>�
  • Best for:�
    • Testing short code snippets�
    • Learning and exploring Python features�
    • Debugging and experimenting�

12 of 25

REPL Example:��>>> 2 + 3

5

>>> print("Hello!")

Hello!

>>> name = input("Enter your name: ")

Enter your name: Alice

>>> print("Welcome", name)

Welcome Alice

  • Limitations of REPL:�
    • Not ideal for long scripts or complex programs.�
    • Code is lost after you close the session.

13 of 25

How to Run Python Scripts

  • What is a Python Script?� A Python script is a file containing Python code, saved with the .py extension. It allows you to write multiple lines of code and save your work.�
  • Creating a Script:�
    • Use any text editor like Notepad, VS Code, PyCharm, or IDLE.�
    • Save the file with a .py extension.�
    • Example: example.py�
  • Running a Script (Using Command Line):�
    • Open Terminal or Command Prompt.�

Navigate to the folder where the .py file is saved.��cd path/to/your/folder

14 of 25

Run the script using:�python example.py or��python3 example.py

  • Running a Script (Using IDEs):�
    • Open the script in IDLE, VS Code, or any Python IDE.�
    • Click Run > Run Module or press F5.�
  • Advantages of Scripts:�
    • Reusable and maintainable code.�
    • Easier to debug and organize.�
    • Can include multiple functions, loops, and logic in one place.

Code Example (greet.py):

name = input("Enter your name: ")

print("Hello", name)

15 of 25

Variables and Assignment in Python

  • What is a Variable?� A variable is a name that refers to a value stored in the computer’s memory. It acts as a container for data.�
  • Dynamic Typing:� Python does not require declaring the type of variable explicitly. The type is inferred based on the value assigned.�
  • Variable Assignment:� Assign a value to a variable using the = operator.

Examples:

x = 10 # Integer variable

name = "Alice" # String variable

price = 99.99 # Float variable

is_valid = True # Boolean variable

16 of 25

  • Rules for Variable Names:�
    • Must start with a letter (a–z, A–Z) or underscore (_).�
    • Can contain letters, digits, or underscores after the first character.�
    • Case-sensitive (name and Name are different).�
    • Cannot use Python keywords (like if, for, while).�
  • Multiple Assignments:�

a, b, c = 1, 2, 3

  • Changing Variable Values:�

x = 5

x = "Hello" # Now x holds a string

17 of 25

Python Keywords

  • What are Keywords?� Keywords are reserved words in Python that have special meaning and cannot be used as variable names, function names, or identifiers.�
  • Purpose of Keywords:� They define the syntax and structure of the Python language.�
  • Examples of Common Python Keywords:�
    • if, else, elif — for conditional statements�
    • for, while, break, continue — for loops and control flow�
    • def, return — for defining and returning from functions�
    • class — for creating classes (object-oriented programming)�
    • import, from — for importing modules�
    • try, except, finally — for exception handling�
    • True, False, None — special constant values�

18 of 25

  • Total Keywords:� Python has about 35 keywords (may vary slightly by version).�

How to See Keywords in Python:�� python�CopyEdit�import keyword

print(keyword.kwlist)

  • Important Notes:�
    • Keywords are case-sensitive (If is not if).�
    • Avoid using keywords as variable names to prevent syntax errors.

19 of 25

Input and Output in Python

  • Output Using print() Function:�
    • The print() function is used to display messages or values on the screen.�
    • You can print text, variables, expressions, and formatted strings.�

Examples:

print("Hello, World!") # Print a string

name = "Alice"

print("Welcome", name) # Print multiple items

print(f"Hello, {name}!") # Using f-string for formatting

  • Input Using input() Function:�
    • The input() function is used to take input from the user as a string.�
    • You can store the input in a variable for later use.�

20 of 25

Example:

age = input("Enter your age: ") # User enters input

print("Your age is", age)

  • Converting Input Types:�
    • Input is always received as a string.�
    • Use type conversion functions like int(), float() to convert input to numbers.�

Example:

num = int(input("Enter a number: "))

print("Number plus 10 is", num + 10)

  • Tips for Input and Output:�
    • Use meaningful prompts to guide users.�
    • Always validate and handle incorrect inputs in real programs.

21 of 25

Indentation in Python

  • What is Indentation?� Indentation is the leading whitespace (spaces or tabs) at the beginning of a line of code used to define the structure and grouping of code blocks.�
  • Why is Indentation Important in Python?�
    • Unlike many languages that use braces {} or keywords to define blocks, Python uses indentation to mark blocks of code (e.g., inside loops, conditionals, functions).�
    • Proper indentation is mandatory; incorrect indentation causes syntax errors.�
  • Indentation Rules:�
    • Consistent use of spaces or tabs (spaces recommended).�
    • Typically, use 4 spaces per indentation level.�
    • All lines of code within the same block must be indented equally.�

22 of 25

  • Example:

if True:

print("This line is indented")

print("So is this line")

print("This line is outside the if block")

  • Common Indentation Errors:�
    • Mixing tabs and spaces.�
    • Missing indentation after statements that require a block (like if, for, def).�
    • Unequal indentation within a block.�
  • Tips:�
    • Configure your code editor to insert spaces when you press Tab.�
    • Use an editor that highlights indentation errors.

23 of 25

24 of 25

25 of 25