KEMBAR78
Introduction to Python and Basic Syntax.pptx
Introduction
to Python
and Basic
Syntax
By
Gv
Objectives:
Understand the basics of Python
programming.
Set up the Python environment.
Write simple Python scripts.
Overview of Python
What is Python?
General Purpose Language
Python is a high-level, interpreted programming
language known for its readability and versatility. It can
be used for a wide range of applications, from web
development to scientific computing.
Easy to Learn
Python’s syntax is clear and intuitive, making it an
excellent choice for beginners while still powerful
enough for experienced programmers.
Interpreted Language
Python is an interpreted language, meaning code is
executed line by line, which can simplify debugging
and development.
Dynamic Typing
Variables in Python do not need explicit declaration to
reserve memory space. The declaration happens
automatically when you assign a value to a variable.
Extensive Standard Library
Python comes with a large standard library that
includes modules and functions for tasks such as file
I/O, system calls, and even web development.
Python Key Features
Readability
Interoperability
Community and Support
Portability
Python's Popularity
Widely used in various domains including
web development, data science, machine
learning, artificial intelligence, and
automation.
Supported by many large companies (e.g.,
Google, NASA, CERN).
Python’s Applications in
Mechatronics
Automation and Control
Robotics
Automated Testing
Data Acquisition and Analysis
Sensor Data Collection
Data Processing
Machine Learning and Artificial Intelligence
Predictive Maintenance
Computer Vision
Simulation and Modeling
System Simulation
Control System Design
Embedded Systems and IoT
Microcontroller Programming
IoT Applications
Visualization and Reporting
Data Visualization
Reporting Tools
Setting Up the Environment
1. Installing Python
Download Python
Go to the official Python website: python.org.
Click on the "Downloads" section.
Choose the version of Python you need (the latest
version is recommended) and download the installer for
your operating system (Windows, macOS, Linux).
Install Python on your
computer.
You can download it from the [official Python
website]
(https://www.python.org/downloads/).
Select Install Now
Installation on Progress
Setup was Successful
Verify the Installation
Open a command prompt (Windows) or terminal
(macOS/Linux).
Type python --version or python3 --version
and press Enter
Setting Up VSCode
Download VSCode
Visit the Visual Studio Code website.
Download the installer for your operating system.
Install VSCode
Run the installer and follow the setup wizard.
Customize the installation settings if necessary.
Setting Up VSCode
Configure VSCode for Python
Open VSCode after installation.
Install the Python extension for VSCode by
Microsoft:
Set the Python interpreter by opening the
Command Palette (Ctrl+Shift+P), typing "Python:
Select Interpreter," and selecting the installed
Python version.
Running Python Scripts
Write a Script:
Open your IDE and create a new file with a
.py extension, e.g., hello.py.
Write a simple Python script
Running Python Scripts
Save the Script:
Save the file in your desired directory.
Run the Script:
Open the command prompt or terminal.
Navigate to the directory where your script is
saved using the cd command.
Run the script by typing python hello.py or
python3 hello.py and pressing Enter. You should
see the output Hello, World!
Variables and Data Types
Integer (int):
Represents whole numbers, positive or negative,
without decimals.
Example: a = 10, b = -3.
Float (float):
Represents real numbers, positive or negative,
with decimals.
Example: pi = 3.14, gravity = 9.8.
Variables and Data Types
String (str):
Represents sequences of characters.
Strings are enclosed in single, double, or triple
quotes.
Example: name = "Alice", message = 'Hello, World!'.
Boolean (bool):
Represents one of two values: True or False.
Useful for conditions and comparisons.
Example: is_valid = True, has_error = False.
Basic Operations
Arithmetic Operations:
Addition (+): result = 5 + 3 (result is 8).
Subtraction (-): result = 5 - 3 (result is 2).
Multiplication (*): result = 5 * 3 (result is 15).
Division (/): result = 5 / 3 (result is approximately 1.6667).
Floor Division (//): result = 5 // 3 (result is 1, discarding the remainder).
Modulus (%): result = 5 % 3 (result is 2, the remainder of the division).
Exponentiation ()**: result = 5 ** 3 (result is 125).
Basic Operations
Logical Operations:
And (and): Returns True if both operands are true.
result = (5 > 3) and (3 < 4) (result is True).
Or (or): Returns True if at least one operand is true.
result = (5 > 3) or (3 > 4) (result is True).
Not (not): Returns True if the operand is false.
result = not (5 > 3) (result is False).
Input and Output Functions
Input Function: Used to take input from the
user.
input(prompt): Reads a line from input,
converts it to a string, and returns it.
Input and Output Functions
Output Function: Used to display output to
the user.
print(): Prints the given object(s) to the
console.
Control Structures in
Python
The primary control structures in Python are:
If Statements
Loops (for, while)
If Statements
If statements allow you to execute a block of
code only if a specified condition is true.
They are used for decision-making in your
code.
Syntax:
Example
Loops
Loops allow you to execute a block of code
multiple times. Python has two main types of
loops: for and while.
For Loops
For loops are used to iterate over a sequence (like a list,
tuple, dictionary, set, or string) and execute a block of code
for each element in the sequence.
Syntax:
Example:
While Loops
While loops execute a block of code as long
as a specified condition is true.
Syntax:
Example:
Combining If Statements
and Loops
Assignment
Write a script to convert temperature units
(Celsius to Fahrenheit).
Write a script to check if a number is prime.
THANK YOU

Introduction to Python and Basic Syntax.pptx

  • 1.
  • 2.
    Objectives: Understand the basicsof Python programming. Set up the Python environment. Write simple Python scripts.
  • 3.
    Overview of Python Whatis Python? General Purpose Language Python is a high-level, interpreted programming language known for its readability and versatility. It can be used for a wide range of applications, from web development to scientific computing.
  • 4.
    Easy to Learn Python’ssyntax is clear and intuitive, making it an excellent choice for beginners while still powerful enough for experienced programmers. Interpreted Language Python is an interpreted language, meaning code is executed line by line, which can simplify debugging and development.
  • 5.
    Dynamic Typing Variables inPython do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. Extensive Standard Library Python comes with a large standard library that includes modules and functions for tasks such as file I/O, system calls, and even web development.
  • 6.
  • 7.
    Python's Popularity Widely usedin various domains including web development, data science, machine learning, artificial intelligence, and automation. Supported by many large companies (e.g., Google, NASA, CERN).
  • 8.
    Python’s Applications in Mechatronics Automationand Control Robotics Automated Testing Data Acquisition and Analysis Sensor Data Collection Data Processing Machine Learning and Artificial Intelligence Predictive Maintenance Computer Vision
  • 9.
    Simulation and Modeling SystemSimulation Control System Design Embedded Systems and IoT Microcontroller Programming IoT Applications Visualization and Reporting Data Visualization Reporting Tools
  • 10.
    Setting Up theEnvironment 1. Installing Python Download Python Go to the official Python website: python.org. Click on the "Downloads" section. Choose the version of Python you need (the latest version is recommended) and download the installer for your operating system (Windows, macOS, Linux).
  • 11.
    Install Python onyour computer. You can download it from the [official Python website] (https://www.python.org/downloads/).
  • 12.
  • 13.
  • 14.
  • 15.
    Verify the Installation Opena command prompt (Windows) or terminal (macOS/Linux). Type python --version or python3 --version and press Enter
  • 16.
    Setting Up VSCode DownloadVSCode Visit the Visual Studio Code website. Download the installer for your operating system. Install VSCode Run the installer and follow the setup wizard. Customize the installation settings if necessary.
  • 17.
    Setting Up VSCode ConfigureVSCode for Python Open VSCode after installation. Install the Python extension for VSCode by Microsoft: Set the Python interpreter by opening the Command Palette (Ctrl+Shift+P), typing "Python: Select Interpreter," and selecting the installed Python version.
  • 19.
    Running Python Scripts Writea Script: Open your IDE and create a new file with a .py extension, e.g., hello.py. Write a simple Python script
  • 20.
    Running Python Scripts Savethe Script: Save the file in your desired directory. Run the Script: Open the command prompt or terminal. Navigate to the directory where your script is saved using the cd command. Run the script by typing python hello.py or python3 hello.py and pressing Enter. You should see the output Hello, World!
  • 21.
    Variables and DataTypes Integer (int): Represents whole numbers, positive or negative, without decimals. Example: a = 10, b = -3. Float (float): Represents real numbers, positive or negative, with decimals. Example: pi = 3.14, gravity = 9.8.
  • 22.
    Variables and DataTypes String (str): Represents sequences of characters. Strings are enclosed in single, double, or triple quotes. Example: name = "Alice", message = 'Hello, World!'. Boolean (bool): Represents one of two values: True or False. Useful for conditions and comparisons. Example: is_valid = True, has_error = False.
  • 23.
    Basic Operations Arithmetic Operations: Addition(+): result = 5 + 3 (result is 8). Subtraction (-): result = 5 - 3 (result is 2). Multiplication (*): result = 5 * 3 (result is 15). Division (/): result = 5 / 3 (result is approximately 1.6667). Floor Division (//): result = 5 // 3 (result is 1, discarding the remainder). Modulus (%): result = 5 % 3 (result is 2, the remainder of the division). Exponentiation ()**: result = 5 ** 3 (result is 125).
  • 24.
    Basic Operations Logical Operations: And(and): Returns True if both operands are true. result = (5 > 3) and (3 < 4) (result is True). Or (or): Returns True if at least one operand is true. result = (5 > 3) or (3 > 4) (result is True). Not (not): Returns True if the operand is false. result = not (5 > 3) (result is False).
  • 25.
    Input and OutputFunctions Input Function: Used to take input from the user. input(prompt): Reads a line from input, converts it to a string, and returns it.
  • 26.
    Input and OutputFunctions Output Function: Used to display output to the user. print(): Prints the given object(s) to the console.
  • 27.
    Control Structures in Python Theprimary control structures in Python are: If Statements Loops (for, while)
  • 28.
    If Statements If statementsallow you to execute a block of code only if a specified condition is true. They are used for decision-making in your code. Syntax:
  • 29.
  • 30.
    Loops Loops allow youto execute a block of code multiple times. Python has two main types of loops: for and while. For Loops For loops are used to iterate over a sequence (like a list, tuple, dictionary, set, or string) and execute a block of code for each element in the sequence.
  • 31.
  • 32.
    While Loops While loopsexecute a block of code as long as a specified condition is true. Syntax: Example:
  • 33.
  • 34.
    Assignment Write a scriptto convert temperature units (Celsius to Fahrenheit). Write a script to check if a number is prime.
  • 35.