WHAT IS PYTHON?
Python is a HIGH-LEVEL PROGRAMMING LANGUAGE used to
create:
Games ,Websites ,Mobile & Desktop Applications ,Data Science & Al
programs .
DEVELOPED BY:-
Guido van Rossum in Year: 1997
FEATURES OF PYTHON
SIMPLE & EASY TO LEARN
PORTABLE (runs on Windows, Linux, Mac)
FREE & OPEN SOURCE
CASE SENSITIVE
(age and Age are different)
HIGH LEVEL LANGUAGE
USES INTERPRETER
DYNAMICALLY TYPED
LARGE STANDARD LIBRARY
PYTHON MODES
1. INTERACTIVE MODE
Commands executed one by one
Output shown immediately
Used for testing and learning
Example:
>>> print(“Hello”)
Output: Hello
2. SCRIPT MODE
Program written in a file
Saved with .py extension
Used for large programs
PRINT FUNCTION:
Print () is used to DISPLAY OUTPUT
On screen.
Example:
Print(“Jai Shree Ram”)
print(“Youth AF”)
BASICS OF PYTHON KEYWORDS
Keywords are RESERVED WORDS
Have special meaning
Cannot be used as variable names
Examples:
If, else, for, while, True, False, None
IDENTIFIERS:-
Name given to a variable
Used to identify data stored in memory
Example:
age = 18
name = "Ayush"
VARIABLES
Used to STORE DATA , No need to declare data type
Example:
A = 5435
B= 6000
NAMING RULES FOR IDENTIFIERS
1. Can start with alphabet or underscore
2. Cannot start with number
No special symbols (@, #, $, %)
Keywords cannot be used Case sensitive
Valid: _age = 10
Name1 = “Ram”
Invalid: 1age = 10
@a = 5
DATA TYPES IN PYTHON:-
Datatypes define the type of data stored in a variable.
1. NUMERIC DATATYPES INT (INTEGER)
Whole numbers Examples:
45, 69, 0, -1, -50
FLOAT
Decimal numbers Examples: 5.24, 2.356, 0.541
COMPLEX
Number with real + imaginary part Example:
5 + 4j ,36 + 2j
BOOLEAN:-
Logical values - True (1) ,False (0)
2. SEQUENCE DATATYPES
STRING
Collection of characters
“Lana” ‘Daniels’
LIST :- Ordered
Changeable
Allows duplicates
Example:
Marks = [45, 67, 89]
TUPLE
Ordered
Unchangeable
Example:
Data = (10, 20, 30)
3. SET :- No duplicate values
Unordered Example:
A = {1, 2, 3}
NONE :-Represents missing or unknown value
X = None
DICTIONARY :- stores data in KEY
Example:
Student = {“name”: “Ayush”,
“age”: 18}
OPERATORS IN PYTHON
Operators perform operations on values.
ARITHMETIC OPERATORS
+ , - , * , /, // , % , **
Example:
10+3 #13
10//3 #3
10%3 #1
2**3 #8
COMPARISON OPERATORS
>,< ,>= ,<= ,== ,!=
Example:
5>3
# True
5 == 3 # False
LOGICAL OPERATORS
And or not
Example:
(5 > 3) and (4 > 2)
ASSIGNMENT OPERATORS
= += -= *= /= //= %=
Example:
A = 10
A += 5
IDENTITY OPERATORS
Is, is not, check memory location
MEMBERSHIP OPERATORS
In, not in
Example:
“a” in “apple”
COMMENTS IN PYTHON
Comments are ignored by Python.
USES:-
•Explain code
•Increase readability
SYNTAX (rule code)
# This is a comment
EXPRESSION
An expression is a combination of values, variables, and operators. Example:
a=5+3*2
INPUT AND OUTPUT
INPUT
Used to take input from user.
Name = input("Enter name: ")
OUTPUT
Displayed using print().
Print(name)
TYPE CONVERSION
Changing one datatype into another.
EXPLICIT CONVERSION
Int(“10”)
Float(5)
Str(25)
IMPLICIT CONVERSION
Python automatically converts data type.
DEBUGGING
Debugging means finding and fixing errors.
COMMON ERRORS
Syntax Error
Name Error
Type Error
Example: @a = 5 # Syntax Error
SUMMARY
Python is easy, powerful & beginner friendly
Variables store data dynamically
Datatypes define data nature
Operators perform operations
Comments - explain code
Debugging fixes errors