0% found this document useful (0 votes)
4 views22 pages

Python Main

This document provides an overview of Python programming, covering its features, variables, conditions, operators, control flow statements, loops, data types, and functions. It includes examples of variable assignment, conditional statements, loop structures, and common methods for various data types. The document serves as a foundational guide for understanding Python basics.

Uploaded by

koushikkotireddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

Python Main

This document provides an overview of Python programming, covering its features, variables, conditions, operators, control flow statements, loops, data types, and functions. It includes examples of variable assignment, conditional statements, loop structures, and common methods for various data types. The document serves as a foundational guide for understanding Python basics.

Uploaded by

koushikkotireddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

PYTHON

BASICS
PYTHON
Python is a high level interpreted
programming language known for its
readability and versatility.
It was created by Guido Van Rossum in 1991.
Main features:
• Easy to learn
• Rich standard library
• Large ecosystem
• Platform independent
• Community and support
VARIABLES
What are variables?
• Stores and manipulates data.
• Symbolic name that refers to a value.
• Memory allocation
• You can use the variable name to access or
modify that value throughout your program.
Variable assignment
'=' is the assignment operator.
Example:
A = 10
Rules for python variables
• Must start with a letter or the
underscore character.
• Cannot start with a number.
• Can contain only alpha-numeric and
underscores.
• Case sensitive
Types of variables
1. Local variables
2. Global variables
3. Nonlocal variables
4. Instance variables
5. Class variables(Static variables)
Other types
6. Constant variables
7. Environment variables
8. Magic variables
CONDITIONS

In Python, conditions are used to make


decisions and execute different blocks of code
based on whether certain conditions are true
or false.
Python provides several constructs for
implementing conditions.

Example:
a = 33
b = 200
if b > a:
print("b is greater than a")
CHAINED
CONDITIONALS

Chained conditionals in Python refer to using multiple if,


elif (else if), and else statements in sequence to evaluate
multiple conditions.
This allows you to execute different blocks of code based
on the outcome of each condition.
Example:
x = -10
if x < 0:
print("The negative number ", x, " is not valid here.")
else:
if x > 0:
print(x, " is a positive number")
else:
print(x, " is 0")
OPERATORS

What are operators?


Operators are special symbols or keywords
that are used to perform operations on
operands.
Operands can be variables, constants, or
expressions.
TYPES OF OPERATORS

Arithmetic Comparison (Relational)


• + Addition • == Equal to
• - Subtraction • != Not equal to
• * Multiplication • < Less than
• / Division • > Greater than
• % Modulus (remainder of • <= Less than or equal to
division) • >= Greater than or equal to
• ** Exponentiation (power)
Logical Assignment
• = Assign value
• and Logical AND
• += Add and assign
• or Logical OR
• -= Subtract and assign
• not Logical NOT
• *= Multiply and assign
• /= Divide and assign
• %= Modulus and assign
• **= Exponentiate and assign
Identity Membership

• is True if both variables point to the same • in True if value is found in the sequence
object • not in True if value is not found in the
• is not True if both variables do not point to sequence
the same object
CONTROL FLOW STATEMENTS( if/else )
Control flow statements in Python are used to alter the flow of execution of a program.
They allow you to make decisions, repeat code blocks, and handle exceptions.
Conditional statements:
• If statements
• Elif statements
• Else statement
Loop control statements:
• Break statement
• Continue statement
• Pass statement
What are loops?
In Python, loops are control flow structures that allow you to
execute a block of code repeatedly based on a condition.
Python supports two main types of loops: for loops and while
loops.
What are iterables?
LOOPS
In Python, an iterable is any object that can be iterated over,
AND ITERABLES meaning it can be used in a loop to iterate through its elements
one at a time.

Loop control statements


Python provides loop control statements like break, continue,
and pass to control the flow of loops.
Types of loops:
• for loop
• while loop
• nested loop
Types of iterables
Common examples of iterables include lists, tuples, strings, dictionaries, sets, and ranges.

Example(While loop):
i=1
while i < 6:
print(i)
if i == 3:
break
i += 1
Example(For loop):
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
DATA TYPES
Numeric:
• Integer(int)
• Float
• Complex
Sequence:
• String(str)
• List
• Tuple
DATA TYPES
Set:
• Set
• Frozen set
Dictionary
Boolean(bool)
None
What is a function?
In Python, a function is a block of reusable code
that performs a specific task.
Functions in Python are defined using the def
keyword followed by the function name,
parentheses (), and a colon :.
Calling a function

FUNCTIONS Calling a function in Python involves using the


function's name followed by parentheses ()
and providing any necessary arguments within
the parentheses.
Return statement
In Python, the return statement is used within a
function to specify the value(s) that the function
should return when it is called.
Example:
def my_function(x):
return 5 * x

print(my_function(3))
print(my_function(5))
print(my_function(9))
Function parameters
Function parameters, also known as function
arguments, are the variables or values that are
passed to a function when it is called.
Function parameters(arguments):
1. Positional parameters
2. Keyword parameters( named parameters)
3. Default parameters
4. Variable-length positional parameters(*args)
5. Variable-length keyword parameters(**kwargs)
6. Positional-only parameters
List methods
• append()
• extend()
• insert()

Common • pop()
• remove()
methods • clear()
• index()
• count()
• sort()
• reverse()
String methods Dictionary methods

• upper() • keys()
• lower() • values()
• capitalize() • items()
• title() • get()
• strip() • pop()
• split() • popitem()
• join() • clear()
• replace() • update()
• startswith()
• endswith()
Tuple methods Set methods

• index() • add()
• count() • remove()
• len() • discard()
• pop()
• clear()
• union()
• intersection()
• difference()
THANK
YOU

You might also like