Introduction to Python and Basic Syntax.pptx

433 views 35 slides Jun 20, 2024
Slide 1
Slide 1 of 35
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35

About This Presentation

Introduction to Python and Basic Syntax
Understand the basics of Python programming.
Set up the Python environment.
Write simple Python scripts
Python is a high-level, interpreted programming language known for its readability and versatility(easy to read and easy to use). It can be used for a wide ...


Slide Content

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
Tags