python
python
WITH PYTHON
DEPT. OF CSE, ASET
• 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/
• In LINUX,
• 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
s= '''I'm a Output
faculty''' I'm a
Print(s) faculty
ACCESSING CHARACTERS IN PYTHON STRING
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
• != : Not equal to
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