mc8jaad98cyzEpUC53EX5B CS NOTES CLASS 12 PYTHON REVISION TOUR
mc8jaad98cyzEpUC53EX5B CS NOTES CLASS 12 PYTHON REVISION TOUR
mc8jaad98cyzEpUC53EX5B CS NOTES CLASS 12 PYTHON REVISION TOUR
NITIN PALIWAL
Page 2
ADVANTAGES OF PYTHON:
DISADVANTAGES OF PYTHON:
Advantages Disadvantages
1. Readability 1. Speed
NITIN PALIWAL
Page 3
Advantages Disadvantages
TOKENS
TOKENS
LITERALS
IDENTIFIERS
KEYWORDS
OPERATORS
Keyword Description
and Logical operator for conjunction (logical AND).
as Used to create an alias for a module or symbol.
assert Used for debugging to check if a condition is true.
break Terminates the loop prematurely.
class Declares a class in object-oriented programming.
continue Skips the rest of the loop's code and continues to the next iteration.
def Defines a function.
del Deletes an object or a part of an object.
elif Stands for "else if" and is used in conditional statements.
else Specifies a block of code to be executed if the condition is false.
except Catches exceptions during exception handling.
False Boolean value representing false.
finally Specifies a block of code to be executed, regardless of the try-except block.
for Used to iterate over a sequence (e.g., list, tuple, string).
from Used to import specific attributes or functions from a module.
global Declares a global variable.
if Conditional statement, executes code if a specified condition is true.
import Imports a module into the current program.
in Membership test, checks if a value exists in a sequence.
is Compares object identity.
lambda Creates an anonymous function (lambda function).
None Represents the absence of a value or a null value.
not Logical operator for negation (logical NOT).
or Logical operator for disjunction (logical OR).
pass Placeholder indicating no action to be taken.
raise Raises an exception.
return Exits a function and returns a value.
True Boolean value representing true.
try Defines a block of code to be tested for errors.
Creates a loop that executes a block of code as long as a specified
while condition is true.
Simplifies resource management (e.g., file handling) using a context
with manager.
Pauses the execution of a generator function and returns a value to the
yield caller.
NITIN PALIWAL
Page 5
IDENTIFIERS
Examples of Identifiers:
Valid:
my_variable
count_1
PI
_underscore
Name123
Invalid:
123abc (starts with a digit)
my-var (contains a hyphen)
if (using a Python keyword)
spaces not allowed
#hash_symbol (contains a special character)
LITERALS
Lists: [1, 2, 3]
LITERAL Tuples: (1, 2, 3)
COLLECTIONS Sets: {1, 2, 3}
Dictionaries: {'key': 'value'}
NITIN PALIWAL
Page 6
PUNCTUATIONS
OPERATORS
IDENTITY Check if two objects are the same. Example: is/ is not
NITIN PALIWAL
Page 7
DATA TYPES
NUMBER
1) Integer DICTIONARY
2) Float
3) Complex Number 1) Unordered collection of key-value pairs.
2) Defined by curly braces ({}) with key-value pairs.
3) Example: person = {'name': 'John', 'age': 25}
STRING
1)
2)
Sequences of characters.
Enclosed in single (' '), double
SET
(" "), or triple quotes. 1) Unordered, mutable collection with unique
3) Example: text = "Hello, World!" elements.
2) Defined by curly braces ({}).
3) Example: unique numbers = {1, 2, 3}
BOOLEAN
1) Represents truth values: True or False.
2) Used for logical operations and
conditions.
TUPLE
3) Example: is_true = True 1) Ordered, immutable collection.
2) Defined by parentheses (()).
3) Example: coordinates = (x, y)
LIST
1) Ordered, mutable collection.
2) Defined by square brackets ([]).
3) Example: numbers = [1, 2, 3]
NITIN PALIWAL
Page 8
CONDITIONAL STATEMENTS
If Statement:
INPUT:
INPUT:
OUTPUT:
NITIN PALIWAL
Page 9
If-Else Statement:
Executes one block of code if a condition is true and another if it's false.
INPUT:
INPUT:
OUTPUT:
OUTPUT:
NITIN PALIWAL
Page 10
If-Elif-Else Statement:
INPUT:
INPUT:
OUTPUT:
NITIN PALIWAL
Page 11
INPUT: OUTPUT:
INPUT: OUTPUT:
NITIN PALIWAL
Page 12
INPUT:
OUTPUT:
NITIN PALIWAL
Page 13
INPUT:
OUTPUT:
NITIN PALIWAL
Page 14
INPUT:
OUTPUT:
NITIN PALIWAL