Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PyDays Day - 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

PyDays Day

Pytho
-1

n
An initiative by Learning
Nexus
• Introduction to Python
• Basic Syntax and
Variables
The agenda of • Data Structures
this • Operators
• Control Flow
Python
• Functions
Bootcamp • Modules and Libraries
• File Handling
• Error Handling
Introduction to
Python
What is
Python?
Python is an interpreted, high-level, general-purpose
programming language. It’s known for its simplicity,
readability, and versatility, often used in web
development, data science, AI, and more.
Why to choose Python?
Python’s syntax is similar to English, making it beginner-
friendly. It has a large, supportive community and
extensive libraries, enabling developers to handle diverse
tasks quickly.
Lets setup Python!
• IDLE (Integrated Development
Enviroment)
• Jupyter Notebook
• Visual Studio Code
Basic Syntaxes and
Variables
Variables and Datatypes
• Variables are containers for storing data
• Python is dynamically typed, meaning you don’t need to
declare variable types:

• Integers: whole numbers, e.g., a = 5


• Floats: decimal numbers, e.g., b = 3.14
• Strings: sequences of characters, e.g., str =
"Hello"
• Booleans: represent True or False, eg., is_empty =
True
Operators
Aritmetic Operators

• ADDITION ( + )
• SUBTRACTION ( - )
• MULTIPLICATION ( * )
• DIVISION ( / )
• FLOOR DIVISION ( // )
• MODULO ( % )
• EXPONENTIATION ( ** ).
Operators
Comparison Operators

• ==
• !=
• <
• >
Operators
LOGICAL OPERATORS
• and
• or
• not
Assignment Operators
• =
• +=
• *=
Control Flow
Conditional statements are essential for controlling the flow of a
program, allowing it to make decisions based on specific
conditions.

Types of conditional statements


• If
• Elif
• Else
Loops

For Loops: While Loops:


for i in condition: while(condition):
statement
statement
Repeat code as long as a
Used for iterating over a condition is true.
sequence.
Loop Control Statement

• break: Exits the loop.


• continue: Skips the current iteration.
• pass: Does nothing; used as a
placeholder.
Functions
Defining Functions
• Functions are blocks of reusable code.
• Defined using the def keyword followed by the function name and
parentheses ().
• Syntax: def function_name(parameters):

Arguments and Parameters


• Arguments are values passed to a function, while parameters are
variables that receive these values.
• Supports default, positional, and keyword arguments for flexibility.
• Enables functions to operate with dynamic inputs.
Scope of Variables

• Local Scope: Variables defined inside a function;


accessible only within that function.
• Global Scope: Variables accessible throughout the
program.
• Use “global” keyword to modify global variables within a
function.
Modules and Libraries
Importing and Using Modules -

• Modules are files containing Python code, functions, and variables.


• Use import module_name or from module import specific_function to access
functionality.
• Commonly used modules include “math”, “datetime”, and “random”.

Overview of Popular Libraries -

• NumPy: For numerical and matrix operations.Supports default, positional, and


keyword arguments for flexibility.
• Pandas: For data manipulation and analysis.
• Matplotlib: For creating visualizations and plots.
File Handling
File Operations and Modes -

• Modes: r (read), w (write), a (append), r+ (read and write).


• open() function is used to open a file in a specific mode.
• Always close a file with close() to free up resources.

Reading from and Writing to Files -

• Reading: Use read(), readline(), or readlines() for reading content.


• Writing: Use write() or writelines() for adding content.
• File operations allow data persistence outside the program’s runtime.
Error Handling

Exception Basics :

• Exceptions occur when an error disrupts normal program


flow.
• Common exceptions: ValueError, TypeError,
IndexError, etc.
• Proper exception handling improves program reliability.
Error Handling

try, except, else, and finally Blocks :

• try: Code that might cause an error.


• except: Code to handle the error if it occurs.
• else: Code that runs if no exception occurs.
• finally: Code that always runs, useful for cleanup tasks.
Thank you
for Joining!
@tnn_vitap

You might also like