0% found this document useful (0 votes)
1 views6 pages

11 Notes Python

The document provides an overview of Python fundamentals, including character sets, tokens, data handling, data types, and operators. It explains the importance of data handling and outlines mutable and immutable data types, as well as various operators used in Python programming. Additionally, it includes examples of code for practical understanding of concepts like even/odd number checking and calculating perimeters.

Uploaded by

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

11 Notes Python

The document provides an overview of Python fundamentals, including character sets, tokens, data handling, data types, and operators. It explains the importance of data handling and outlines mutable and immutable data types, as well as various operators used in Python programming. Additionally, it includes examples of code for practical understanding of concepts like even/odd number checking and calculating perimeters.

Uploaded by

koushikvansh67
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CH- PYTHON Example:

x = 10
FUNDAMENTALS y = 20

D. Special Symbols

Some commonly used symbols are:


1. PYTHON + - * / % = >
CHARACTER SET <
'
( ) [ ] { }
" : ; #
@ & !
Introduction Example:
A Character Set is a collection of all valid characters a = b + c
that can be used to write a Python program. Python
follows the Unicode Character Set, allowing
programmers to write programs in many languages. Rules Related to Character Set
Every Python program consists of characters, and each  Python is case-sensitive.
character has a specific meaning.  Name and name are different variables.
 Only valid characters can be used.
Types of Characters in Python Example:
A. Letters (Alphabets) Name = "Aman"
name = "Rohan"
Python allows both uppercase and lowercase English
print(Name)
letters. print(name)

 Uppercase: A–Z Output


 Lowercase: a–z
Aman
Examples: Rohan

name = "Rahul"
city = "Delhi" 2. TOKENS IN PYTHON
B. Digits (Numbers) Definition
Digits from 0 to 9 are used. Tokens are the smallest individual units of a Python
program.
Example:
A Python program is made up of different types of
age = 17 tokens.
marks = 95
Example
C. White Spaces
a = 20
White spaces improve readability.
Tokens are:
They include:
a
=
 Space 20
 Tab
 New Line
Types of Tokens
Python has six main types of tokens. _marks

1. Keywords Invalid

1roll
Keywords are reserved words having predefined my name
meanings. class

They cannot be used as variable names. 3. Literals


Examples Literals are fixed values.
if
else Examples
while
for 100
True 3.14
False "Python"
None True
break
continue Types of literals
class
def
return  Integer
import  Float
 String
Example  Boolean
 Complex
if marks >= 40:
print("Pass")
4. Operators
2. Identifiers Operators perform operations.

Identifiers are names given to: Example

 Variables a + b
 Functions
 Classes Operator
 Objects
+
Example

student_name = "Amit" 5. Delimiters (Separators)


totalMarks = 450
They separate different parts of a program.
Rules for Identifiers
Examples
✔ Can contain letters, digits and underscore
()
✔ Cannot start with a digit []
{}
,
✔ Cannot contain spaces :
.
;
✔ Cannot use keywords
Example
✔ Case-sensitive
print("Hello")
Valid

roll_no 6. Comments
student1
Comments explain the code. Examples

Python ignores comments. age = 18


salary = 50000
Single-line comment
2. Float
# This is a comment
Stores decimal numbers.

3. DATA HANDLING
Examples

pi = 3.14159
weight = 62.5
Definition
3. Complex
Data Handling means storing, processing, modifying
and managing data in a program. Stores complex numbers.

Python provides different data types to store different Example


kinds of data.
z = 4 + 5j
Why Data Handling is Important?
4. Boolean
 Store information
 Perform calculations Stores only
 Process user input
True
 Manage records False
 Build applications
Example
Example
result = True
name = "Riya"
age = 17
marks = 94.5 5. String

Different kinds of data are stored using different data Stores text inside quotes.
types.
Example

4. DATA TYPES city = "Meerut"

6. List
Definition
Ordered collection.
A Data Type specifies the kind of value stored in a
variable. Mutable.
Example Example
x = 25 fruits = ["Apple","Mango","Orange"]

Integer Data Type


7. Tuple

Types of Data Types Ordered collection.

1. Integer (int) Immutable.

Stores whole numbers. Example


days = ("Mon","Tue","Wed") numbers = [10,20,30]

[Link](40)
8. Set
print(numbers)
Unordered collection.
Output
No duplicate values.
[10,20,30,40]
Example
Dictionary Example
A = {2,4,6}
student = {"Name":"Riya"}
9. Dictionary student["Age"] = 17

Stores data in key-value form.


Set Example
Example A = {2,4}

student = { [Link](6)
"name":"Amit",
"Age":17
} Immutable Data Types

Data Type Summary Immutable means cannot be changed after creation.

Examples
Data Type Example Mutable
Integer 25 No  Integer
 Float
Float 5.6 No
 String
Boolean True No  Tuple
String "Python" No  Boolean
List [1,2,3] Yes  Complex
Tuple (1,2,3) No
Example
Set {1,2,3} Yes
Dictionary {"A":10} Yes name = "Python"

name[0] = "J"

5. MUTABLE AND Output

IMMUTABLE DATA TypeError

TYPES Tuple Example

t = (10,20,30)
Mutable Data Types t[1] = 50

Mutable means can be changed after creation. Error because tuple is immutable.
Examples
Difference Between Mutable and
 List Immutable
 Dictionary
 Set
Mutable Immutable
Example Can be modified Cannot be modified
Mutable Immutable Example
New object created on
Faster for updates print(15 > 8)
modification
List, Set, String, Tuple, Integer, Float, Output
Dictionary Boolean
True

6. OPERATORS IN 3. Assignment Operators

PYTHON Operator Example


= a=5
+= a+=2
Definition -= a-=2
*= a*=2
Operators are symbols used to perform operations on
data. /= a/=2
%= a%=2
Types of Operators
Example
1. Arithmetic Operators x = 10

Operator Meaning Example x += 5


+ Addition 5+3 print(x)
- Subtraction 8-2
* Multiplication 4*6 Output
/ Division 9/3
15
% Modulus 9%2
// Floor Division 9//2 4. Logical Operators
** Exponent 2**3
Operator Meaning
Example and Both conditions true
or Any one condition true
a = 12
b = 5 not Opposite result

print(a+b)
print(a-b) Example
print(a*b)
print(a/b) a = 10
print(a%b) b = 20
print(a//b)
print(a**b) print(a < b and b > 15)

2. Relational (Comparison) Operators Output

True
Used to compare values.
5. Membership Operators
Operator Meaning
== Equal Used to check membership.
!= Not Equal
> Greater Than Operator Meaning
< Less Than in Present
>= Greater Than Equal not in Not Present
<= Less Than Equal
Example print("Even Number")
else:
list1 = [10,20,30] print("Odd Number")

print(20 in list1) 2. Leap Year


Output year = int(input("Enter a year: "))

True if (year % 400 == 0) or (year % 4 == 0 and


year % 100 != 0):
print(year, "is a Leap Year")
6. Identity Operators else:
print(year, "is not a Leap Year")
Compare object identity.
4. Addition of Two Numbers
Operator Meaning
num1 = float(input("Enter first number: "))
is Same object num2 = float(input("Enter second number: "))
is not Different object
sum = num1 + num2

Example print("Addition =", sum)

x = [1,2]
y = x 5. Square of a Number

print(x is y) num = float(input("Enter a number: "))

square = num * num


Output
print("Square =", square)
True
6. Cube of a Number
num = float(input("Enter a number: "))
7. Bitwise Operators (Advanced) cube = num * num * num

Operator Meaning print("Cube =", cube)


& AND
7. Perimeter of a Rectangle
| OR
^ XOR Formula:
~ NOT
<< Left Shift length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
>> Right Shift
perimeter = 2 * (length + breadth)
Example print("Perimeter of Rectangle =", perimeter)
print(5 & 3)
8. Perimeter of a Square
Output
Formula:
1
side = float(input("Enter side of square:
"))

SOME EXAMPLES OF CODE perimeter = 4 * side

print("Perimeter of Square =", perimeter)


1. Even or Odd Number
num = int(input("Enter a number: "))

if num % 2 == 0:

You might also like