0% found this document useful (0 votes)
5 views30 pages

python

The document provides an introduction to Python programming, covering its features, applications, and basic concepts such as variables, data types, and operators. It includes examples of Python programs and explains how to install Python and use online interpreters. The document also highlights the importance of Python modules and the math module for mathematical tasks.

Uploaded by

shilpasivadas
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)
5 views30 pages

python

The document provides an introduction to Python programming, covering its features, applications, and basic concepts such as variables, data types, and operators. It includes examples of Python programs and explains how to install Python and use online interpreters. The document also highlights the importance of Python modules and the math module for mathematical tasks.

Uploaded by

shilpasivadas
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/ 30

FDP ON ALGORITHMIC THINKING

WITH PYTHON
DEPT. OF CSE, ASET

🚀 WELCOME TO THE WORLD OF


PYTHON! 🐍
CONTENTS

• Introduction to python
• Variables
• Numeric and string datatypes
• Math module
• Python standard library for basic I/O
• Python operators and precedence
INTRODUCTION
• Python is a high-level, interpreted programming
language.
• It is renowned for its readability and efficiency.
• Python's syntax is simple and similar to the English
language.
• It supports multiple programming paradigms,
including object-oriented, procedural, and functional
programming.
• Python is versatile, used for web development, data
analysis, artificial intelligence, and more.
APPLICATIONS
1. Web development
2. Machine learning and artificial intelligence
3. Data science
4. Game development
5. Audio and visual applications
6. Software development
7. CAD applications
8. Business applications
9. Desktop GUI
10. Web scraping application
GETTING STARTED.. INSTALL PYTHON
• https://www.python.org/downloads/

FOR WINDOWS, LINUX, MAC

• In LINUX,

sudo apt install python 3.13


ONLINE PYTHON INTERPRETERS

• https://www.online-python.com/
• https://www.onlinegdb.com/online_python_interpreter
• https://onecompiler.com/python
• https://www.w3schools.com/python/python_compiler.as
p
• https://pycompile.com/
• https://www.programiz.com/python-programming/onlin
e-compiler/
VARIABLES IN PYTHON
• Variables act as placeholders for data.
• A variable is essentially a name that is assigned to a value.
• Variables are used to store data that can be referenced and
manipulated during program execution.
Rules for naming variables
• Variable names can only contain letters, digits and
underscores (_).
• A variable name cannot start with a digit.
• Variable names are case-sensitive (myvar and Myvar are
different).
EXAMPLES
•x=5
• y = 3.14
• z = "hi "
• num1=17.5
• a = b = c = 100

• print(type(x)) -int
• print(type(y)) -float
• print(type(z)) -string
FEATURES OF VARIABLES
• Dynamic typing
• No declaration needed
• Case sensitive

Type casting
Type casting refers to the process of converting the value of
one data type into another.
s = "10"
n = int(s)
Example python programs
• Program to print “ Hello, world!”
Print('hello, world!’)
Output: Hello, world!
• Program to find the Sum of 2 numbers
num1=5
num2=7
Print(num1+num2)
Output-12
Example python programs
• Python program to find the area of a circle

r = 5 # radius

pi=3.14

area = pi*r*r

print(area)

output- 78.5
DATA TYPES
• Data types define the kind of value a variable can hold
NUMERIC AND STRING DATA TYPES

• Numeric types are used to store numbers. Python


supports the following numeric types:
• Int: represents integers (whole numbers).
Example: x = 10, y = -5
• Float: represents floating-point numbers (decimal
values).
Example: pi = 3.14, temp = -0.75
• Complex: represents complex numbers with real and
imaginary parts.
• The string data type is used to store sequences of characters,
enclosed in either single (') or double (") quotes.
Example: Name = "alice"
Greeting = 'hello, world!'
• Strings are immutable, meaning their content cannot be
changed after creation.
• Python provides a rich set of methods for string manipulation,
such as:
Upper(): converts to uppercase.
Lower(): converts to lowercase.
Example-1: text = "hello, world!"
uppercase_text = text.upper()
print("uppercase text:", uppercase_text)
Output-HELLO, WORLD!
Example-2: text = "hello, world!”
updated_text = text.replace("world", "universe")
print(updated_text)
Output-hello, universe!
• Example:
text = " python "
print(text.strip().upper()) # output: "PYTHON“
• Strings can be concatenated using the + operator, while
numeric types can be added, subtracted, multiplied, etc.
• Example:
str1 = "hello"
str2 = "world"
result = str1 + " " + str2
print(result) output: hello world
• Python treats anything inside quotes as a string. This
includes letters, numbers, and symbols.
• s= "gfg"
• Print(s[1]) # access 2nd char
• s1 = s + s[0] # update ie. Add g to gfg
• Print(s1) # print
• Output
f
gfgg
MULTI-LINE STRING
s = """I am learning Output
Python string on I am learning
THIS FDP""" Python string on
Print(s) THIS
FDP

s= '''I'm a Output
faculty''' I'm a
Print(s) faculty
ACCESSING CHARACTERS IN PYTHON STRING

• Strings are indexed starting from 0 and -1 from the


end. This allows us to retrieve specific characters from
the string.
PYTHON MODULES
• In Python, modules are files containing Python code
(functions, classes, or variables) that can be imported and
reused in other Python programs.
• They help organise code into manageable sections and
promote reusability.

PYTHON MATH MODULE


• Python has a built-in module that you can use for
mathematical tasks.
• The math module has a set of methods and constants.
math.pow() Returns the value of x to the power of y
math.log() Returns the natural logarithm of a number, or
the logarithm of number to base

math.factorial() Returns the factorial of a number


math.exp() Returns E raised to the power of x

math.cos() Returns the cosine of a number

math.tan() Returns the tangent of a number


PYTHON PROGRAM TO FIND SQUARE ROOT OF A
NUMBER USING MATH MODULE

import math
number = 16
sqrt_value = math.sqrt(number)
print(sqrt_value)

• Output-4
OPERATORS IN PYTHON
• Operators are special symbols or keywords used to
perform operations on variables and values.
Arithmetic Operators

+ : Additiona+b
•- : Subtraction a-b
•* : Multiplication a*b
•/ : Division a/b

•% : Modulus (remainder) a%b


•** : Exponentiation (power) a**b

•// : Floor division (quotient without remainder) a//b


Comparison (relational) operators
• == : Equal to

• != : Not equal to

• > : Greater than

• < : Less than

• >= : Greater than or equal to

• <= : Less than or equal to


Logical Operators
•and : Logical AND
•or : Logical OR
•not : Logical NOT

Bitwise Operators
•& : Bitwise AND
•| : Bitwise OR
•^ : Bitwise XOR
•~ : Bitwise NOT
•<< : Left shift
•>> : Right shift
Assignment Operators
•= : Assign value
•+= : Add and assign

Membership Operators
•in : Checks if a value is present in a sequence
•not in : Checks if a value is not present in a sequence

Identity Operators
•is : Checks if two variables refer to the same object
•is not : Checks if two variables do not refer to the same object
Special Operators
•Ternary Opersator
n=5
res = “Positive" if n >0 else “Negative"
print(res)

Output-Positive

These operators allow Python to handle a wide range of


operations, from basic arithmetic to complex logical and
bitwise manipulations.
OPERATOR PRECEDENCE
• Expr = 10 + 20 * 30
Output-610
• print(5 - (2 + 3))
Output-0
• print(5 - 2 + 3)
Output-6
THANK YOU 

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy