Computer Science Notes - Introduction to Python
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability. It
is widely used in web development, data science, artificial intelligence, automation, and more.
Features of Python: - Easy to learn and use - Interpreted language (no need for compilation) -
Platform independent - Large standard library - Supports Object-Oriented Programming
2. ASCII Codes
ASCII (American Standard Code for Information Interchange) is a character encoding standard.
Each character (letters, digits, symbols) is represented by a numeric value. Examples: A = 65 a =
97 0 = 48 Space = 32 In Python: ord('A') gives ASCII value of A. chr(65) gives character for ASCII
value 65.
3. Tokens in Python
Tokens are the smallest individual units in a program. Types of Tokens: 1. Keywords: Reserved
words with special meaning. Examples: if, else, for, while, True, False 2. Identifiers: Names given to
variables, functions, etc. Rules: - Must start with letter or underscore - Cannot use keywords - Case
sensitive 3. Literals: Fixed values in a program. Examples: Integer: 10 Float: 3.14 String: "Hello"
Boolean: True 4. Operators: Used to perform operations. Arithmetic: +, -, *, / Comparison: ==, !=, >,
< Logical: and, or, not 5. Punctuators: Symbols used for structure. Examples: (), {}, [], :, ,
4. Explicit and Implicit Type Conversion
Implicit Conversion: Python automatically converts one data type into another. Example: a = 5 b =
2.0 c = a + b # Result is float Explicit Conversion (Type Casting): User manually converts data type
using functions. int() -> Converts to integer float() -> Converts to float str() -> Converts to string
bool() -> Converts to boolean Example: x = "10" y = int(x)
5. print() and input() Functions
print() function: Used to display output on the screen. Example: print("Hello World") input() function:
Used to take input from user. It always returns data as string. Example: name = input("Enter your
name: ") age = int(input("Enter your age: "))
6. Programming Constructs
1. if-else: Used to make decisions. Example: if age >= 18: print("Adult") else: print("Minor") 2.
if-elif-else: Used when multiple conditions are present. Example: if marks >= 90: print("Grade A")
elif marks >= 75: print("Grade B") else: print("Grade C") 3. for loop: Used for iteration. Example: for i
in range(5): print(i) range(start, stop, step) can also be used.