0% found this document useful (0 votes)
1 views

PYTHON PROGRAMMING.pptx (1)

Python is a high-level, interpreted programming language known for its simplicity and readability, created by Guido van Rossum in 1991. It is widely used in various fields such as web development, data science, and automation, and features two main modes: script mode for larger programs and interactive mode for quick testing. The document also covers Python syntax, data types, operators, functions, and file handling, providing essential information for beginners and developers.

Uploaded by

smasherscode812
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

PYTHON PROGRAMMING.pptx (1)

Python is a high-level, interpreted programming language known for its simplicity and readability, created by Guido van Rossum in 1991. It is widely used in various fields such as web development, data science, and automation, and features two main modes: script mode for larger programs and interactive mode for quick testing. The document also covers Python syntax, data types, operators, functions, and file handling, providing essential information for beginners and developers.

Uploaded by

smasherscode812
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

"Introduction to

What is Python?
Python"
Python is a high-level, interpreted programming language known for its
simplicity and readability.

It was created by Guido van Rossum and first released in 1991.

Python has a simple syntax similar to English, making it easy to read and
write.

It is used in various fields like web development, data science, machine


learning, automation, and more.
Guido van
Why should
we learn
Python
coding?
Python is designed to be highly readable and
beginner-friendly.

It allows developers to focus on solving problems


rather than worrying about complex syntax.

It is a cross-platform language that runs on various


operating systems like Windows, Mac, and Linux.
“Installation of Python
Idle”
Windows

1. Download Python:
Go to the official Python website.
Download the latest version of Python (look
for the Windows installer).
2. Run the Installer:
Open the downloaded installer.
Check the box that says “Add Python to
PATH.”
Click on “Install Now.”
Python Modes
Python has two main modes:
1. script mode
2. interactive mode:

Interactive mode
In this mode, you type commands and they are
immediately executed. It's best for testing and
experimenting with Python, and for quick
debugging. Interactive mode is also useful for
exploratory programming and prototyping.
However, it's not recommended for writing long
pieces of code or scripts that span multiple
files.
Script mode
In this mode, you put a series of
commands into a file, and then tell
Python to run the file. It's best for
developing and running more
substantial Python programs, and
for automating tasks and creating
standalone applications. Script
mode also allows you to save your
code in a file for future use.
Syntax Of Python
Python syntax refers to the set of rules that defines how Python code is written and
structured. Here are some key elements of Python syntax:

Variables
Variables are used to store data values.

Control Flow
Python includes several control flow statements:
if statements:
z=3
if z % 2 == 0:
print("z is divisible by 2")
elif z % 3 == 0:
print("z is divisible by 3")
else:
print("z is neither divisible by 2 nor by 3")
for loops:
for i in range(5):
print(i)

while loops:
With the while loop we can execute a set of statements as long as a
condition is true.
i=1
while i < 6:
print(i)
i=i+1
PYTHON TOKENS
"Tokens" refer to the smallest units of code that the Python interpreter
recognizes. These include keywords, identifiers, literals, operators, and
delimiters. Here’s a quick overview:

Keywords: Reserved words that have special meaning in Python


(e.g., if, else, while, def, class).
Identifiers: Names you give to variables, functions, classes, etc.
(e.g., my_variable, calculate_total).
Literals: Fixed values that you use directly in your code (e.g., 42,
3.14, "hello").
Operators: Symbols that perform operations on variables and
values (e.g., +, -, *, /).
Delimiters: Symbols that help structure the code (e.g., parentheses
(), brackets [], braces {}, commas ,, colons :).
PYTHON
OPERATORS
In Python, operators are special
symbols that perform operations on
variables and values. They can be
categorized into several types:
1. Arithmetic
Operators
These operators perform basic
mathematical operations.
+ : Addition
- : Subtraction
* : Multiplication
/ : Division (float)
// : Floor Division
% : Modulus (remainder)
** : Exponentiation (power)
2. Comparison
Operators(Relational
Operator)

These operators compare two values


and return a boolean result.

== : Equal to
!= : Not equal to
> : Greater than
< : Less than
>= : Greater than or equal to
<= : Less than or equal to
3. Logical
Operators
These operators are used to
combine conditional statements.
4.
PYTHON DATA TYPES:
There are five major data types in python:

1. List
2. String
3. Tuple
4. Numbers
5. Dictionary
STRINGS
IN PYTHON
In Python, a string is a sequence of characters
used to represent text. Strings can include
letters, numbers, symbols, and whitespace. They
are one of the fundamental data types in Python
and are defined by enclosing characters in either
single quotes ('), double quotes ("), triple single
quotes ('''), or triple double quotes (""").

greeting = "Hello"
name = "Alice"
message = greeting + ", " + name + "!"
print(message) # Output: Hello, Alice!
LISTS IN PYTHON
In Python, a list is a built-in data structure that
allows you to store an ordered collection of
items. Lists can hold a variety of data types,
including integers, floats, strings, and even other
lists. They are mutable, meaning you can change
their contents without creating a new list.

For example:
fruits.append("mango")
fruits.insert(1, "blueberry") # Inserts
'blueberry' at index 1
TUPLES IN PYTHON
In Python, a tuple is a built-in data
structure that is similar to a list, but
with a key difference: tuples are
immutable. This means that once a
tuple is created, its contents cannot be
changed. Tuples are typically used to
group related data together.

For example:
fruits = ("apple", "banana", "cherry")
print(fruits[0]) # Output: 'apple'
print(fruits[1]) # Output: 'banana'
Difference between
Lists and Tuples
DICTIONARY IN PYTHON
In Python, a dictionary is a built-in data
structure that stores data in key-value pairs.
Dictionaries are unordered, mutable, and
indexed by keys, which can be of any
immutable type (like strings, numbers, or
tuples). They are particularly useful for
scenarios where you want to associate values
with unique keys.
For example:
my_dict = { "name": "Alice", "age": 30, "city": "New York" }
another_dict = dict(name="Bob", age=25, city="Los Angeles")
print(my_dict["name"]) # Output: Alice
print(my_dict["age"]) # Output: 30
FUNCTIONS
In Python, a function is a reusable block of code that performs a specific task. Functions help organize
code, make it more readable, and avoid repetition. They can take inputs (arguments) and return outputs.

There are two types of scope in python


1.local scope
2.global scope

Th
DATA FILE HANDLING
File handling in Python allows you to read from and write to files, which is essential
for data persistence and manipulation. Python provides built-in functions to work
with files easily. Here’s a comprehensive overview of file handling in Python.

File Modes
Here are some common file modes:
'r': Read (default mode). Opens a file for reading.
'w': Write. Opens a file for writing (creates a new
file or truncates an existing one).
'a': Append. Opens a file for appending (writes
data at the end of the file).
'b': Binary mode. Can be added to any mode to
handle binary files (e.g., 'rb', 'wb').
TEXT FILES
Python involves various operations, such as
creating, reading, writing, and appending
data. Here's a detailed overview of how to
handle text files in Python, including
examples.
BINARY FILES
In Python, binary files are files that contain
data in a format that is not plain text. These
files can include images, audio, video, and other
types of data that require specific encoding.
When working with binary files, it's essential to
use binary modes for reading and writing.
STACK
Stack means arranging one object over another
and this object are remove in reverse order of
their arrival .The stack is called Last In First
Out(LIFO) arrangement. You can implement a
stack using lists.

Basic Operations and Implementation of


Stack
Stack is open at one end, so operations can be
performed on single end. We have two primitive
operations that can be performed on stack data
structure :
Push Operation:
The "push" operation in the context of a stack refers to adding an
item to the top of the stack. In Python, you typically use the
append method to perform this operation. If stack is full it will
return “OVERFLOW”.
For example:
# Create a stack using a list
stack = []

# Push items onto the stack


stack.append(1) # Push 1
stack.append(2) # Push 2
stack.append(3) # Push 3

print("Stack after pushes:", stack)


Pop Operator
Here "pop" operation in a stack refers
to removing the item from the top of
the stack. In Python, you can use the
pop method for this purpose. If stack is
empty it will return “UNDERFLOW”.

For example:
stack = [1, 2, 3]
top_item = stack.pop()
print("Popped item:", top_item)
.

THANK YOU

You might also like