Python
ADD TITLE
Fundament
als Add Subtitle
TOKENS
🔹 Definition:
.
Tokens are the smallest building blocks of a Python program
.
🔹 Explanation:
•Every instruction in Python is broken down into tokens.
•They are like the words of the Python language.
•Without tokens, Python code cannot be interpreted.
⚡ In short: A Python program is made up of tokens, just like a sentence is made up of words.
2
Types of tokens
Punctuat
Keywor
ors
ds
Identifi Operato
ers rs
Litera
3 ls
Types of Tokens
Keywords Identifiers
🔹 Definition: 🔹 Definition:
Keywords are predefined reserved words in Identifiers are the names given to variables, functions,
Python that have special meaning. classes, or other objects in Python
.
🔹 Key Points: 🔹 Rules for Identifiers:
•They are used to define the syntax and • First character must be letters; the underscore ( _ )
structure of Python programs. • Cannot start with a digit.
• Case-sensitive (name and Name are different).
•Cannot be used as identifiers (variable, • Cannot be a keyword (e.g ., if, class).
function, or class names). • Cannot contain special character and
whitespace
•They are case-sensitive (e.g., if is valid,
but If is not a keyword). 🔹 Examples:
🔹 Examples: ✅ Valid: my_var, student1, totalMarks
if, else, while, for, class, def, return, ❌ Invalid: 1name, for, my var,s@rthak
⚡ Identifiers are like
import
OPERATORS
🔹 Definition 🔹
Operators are special symbols in Python used to perform operations on values and variables.
The values on which operators act are called operands.
Types of
operators
Unary Binary
operators operators
Unary operators are Binary operators are
those operators which those operators which
require only one require two operands
operand to operate to operate upon
+Unary upon
plus -Unary minus
-Bitwise complement not logical
negation
5
Literals
🔹Definition: 🔹
Literals are the constant values that are directly written in a Python program to represent data
🔹 Key Points:
•They are fixed values, not variables.
•Python uses literals to assign values to identifiers (variables, constants, etc.).
Types of
literals
Boolean
literals Literal
Numeric collecti
literals String Special ons
6 literals literal
None
7
Types of Literals
Numeric literals String literals Special literal
A string literal is a sequence
These represent numbers. of one or more characters none
Definition: None is a special
Python classifies them into enclosed within quotes. literal in Python used to
three categories: Types of String Literals represent the absence of a
value or a null reference.
Integer Literals → Whole Single Quotes (‘ ’) → 'Hello’ Key Properties: None is an
numbers without a decimal Double Quotes (“ ”) → object of its own datatype:
point. Examples: 0, 10, -250, "Python“ NoneType. It is not the same
999999 Triple Quotes (‘’’ ’’’ or “”” as 0, False, or an empty
“””) → Used for multiline text. string "". Often used for
Floating-Point Literals → default values, function
Numbers with a decimal point Example: msg = """This is a return values, or
or in exponential form. multiline string""" placeholders
Examples: 3.14, -0.99, 2.5e3 Key Points:
(which means 2500.0) • Strings are immutable
(cannot be changed after
Complex Literals → Numbers creation).
with a real and an imaginary • Strings can contain letters,
part (denoted with j). numbers, symbols, or even
Examples: 5+7j, -3.5j spaces.
8
PUNCTUATORS
🔹 Definition:
Punctuators (also called delimiters) are symbols that give structure to Python code. They help
group, separate, or organize statements and expressions
. Common Punctuators
•Parentheses ( ) → Used in functions, expressions, tuples.
•Example: print("Hello"), (1, 2, 3)
•Brackets [ ] → Used for lists, indexing, slicing.
•Example: mylist[0], [10, 20, 30]
•Braces { } → Used for dictionaries and sets.
•Example: {'a': 1, 'b': 2}, {1, 2, 3}
•Comma , → Separates items.
•Example: a, b, c = 1, 2, 3
•Colon : → Used in functions, loops, dictionaries.
•Example: if x > 5:, {'a': 10}
•Semicolon ; → Separates multiple statements in one line.
•Example: x = 5; y = 10
•Period . → Used for accessing methods or attributes.
•Example: math.sqrt(16)
•Ellipsis ... → Used for advanced slicing and as a placeholder.
•Example: mylist[1:...]
Insert Image
Variable
Definition: Variables are names used to store data in memory.
Key Points:
• Created when you assign a value (x = 10).
• No need to declare type (Python is dynamically typed).
• Variable name must follow identifier rules.
Example:
name = "Sarthak" age = 16
9
SIMPLE INPUT AND OUTPUT
•Input Function: Used to take user input. Always returns a string.
name = input("Enter your name: ")
•Output Function: print() is used to display output.
print("Welcome", name)
•Key Point: Input/Output makes programs interactive.
10