0% found this document useful (0 votes)
3 views5 pages

Introduction to Python Notes 1

This document provides an introduction to Python, covering its history, features, installation steps, basic syntax, data types, operators, user input, and basic I/O operations. It highlights Python's simplicity, versatility, and extensive ecosystem, along with practical examples of variables, data types, and operators. The document concludes with a quick recap of key concepts and functionalities in Python.

Uploaded by

monsterrockey57
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)
3 views5 pages

Introduction to Python Notes 1

This document provides an introduction to Python, covering its history, features, installation steps, basic syntax, data types, operators, user input, and basic I/O operations. It highlights Python's simplicity, versatility, and extensive ecosystem, along with practical examples of variables, data types, and operators. The document concludes with a quick recap of key concepts and functionalities in Python.

Uploaded by

monsterrockey57
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

Introduction to Python — Study Notes

1. Overview of Python

History of Python

Year Event

Late 1980s Conceived by Guido van Rossum at CWI, Netherlands

1991 Python 0.9.0 released

2000 Python 2.0 released (list comprehensions, garbage collection)

2008 Python 3.0 released (not fully backward-compatible with 2.x)

Today Python 3.x is the actively maintained version

Name origin: Named after the British comedy show "Monty Python's Flying Circus" — not the snake!

Features of Python

Easy to Learn & Read – syntax close to plain English


Interpreted – executes line by line (no separate compilation step)
Dynamically Typed – no need to declare variable types
Free & Open Source
High-Level Language – abstracts away memory management
Portable – runs on Windows, macOS, Linux without change
Extensive Standard Library ("batteries included")
Supports Multiple Paradigms – procedural, object-oriented, functional
Huge Ecosystem – NumPy, Pandas, Django, TensorFlow, etc.

WHY PYTHON?
┌─────────────────────┐
│ Simple │ Free │
│ Readable│ Powerful │
│ Popular │ Versatile │
└─────────────────────┘

2. Installing Python & Setting Up the Environment

Steps to Install

1. Go to [Link]
2. Download the installer for your OS (Windows/macOS/Linux)
3. Important: While installing on Windows, check ✅ "Add Python to PATH"
4. Verify installation using terminal/command prompt:

python --version
# or
python3 --version

Setting Up the Environment

IDLE – comes bundled with Python (simple editor)


Popular IDEs/Editors: VS Code, PyCharm, Jupyter Notebook
Running a Python file:

python [Link]
Interactive Mode (Python Shell) – type python in terminal to get >>> prompt and run code line by line.

3. Basic Syntax

Variables

A variable is a name that refers to a value stored in memory.


No need to declare data type (Python infers it automatically).

name = "Alice" # string


age = 20 # integer
height = 5.6 # float

Rules for naming variables: - Must start with a letter or underscore ( _ ), not a digit - Can contain letters, digits, underscores - Case-
sensitive ( Age and age are different) - Cannot use Python keywords as variable names

Constants

Python has no built-in constant type — by convention, constants are written in UPPERCASE.

PI = 3.14159
MAX_LIMIT = 100

Keywords

Reserved words that have special meaning in Python; cannot be used as identifiers.

import keyword
print([Link])

Examples: if , else , while , for , def , class , True , False , None , import , return

4. Data Types in Python

Python Data Types



┌───────────────┼───────────────┐
│ │ │
Numeric Sequence Mapping & Set
┌────┴────┐ ┌─────┼─────┐ │
int float str list tuple dict / set

Data Type Description Example Mutable?

int Whole numbers x = 10 No

float Decimal numbers y = 10.5 No

str Text/sequence of characters s = "hello" No

list Ordered, changeable collection [1, 2, 3] Yes

tuple Ordered, unchangeable collection (1, 2, 3) No

dict Key-value pairs {"a": 1} Yes

set Unordered, unique elements {1, 2, 3} Yes

a) Integers & Floats

a = 25 # int
b = 3.14 # float
print(type(a), type(b)) # <class 'int'> <class 'float'>
b) Strings

s = "Hello World"
print(s[0]) # H (indexing)
print(s[0:5]) # Hello (slicing)
print([Link]()) # HELLO WORLD
print(len(s)) # 11

c) Lists — Ordered & Mutable

fruits = ["apple", "banana", "cherry"]


[Link]("mango") # add item
fruits[0] = "kiwi" # modify item
print(fruits) # ['kiwi', 'banana', 'cherry', 'mango']

d) Tuples — Ordered & Immutable

coordinates = (10, 20)


print(coordinates[0]) # 10
# coordinates[0] = 15 # ❌ Error: tuples cannot be changed

e) Dictionaries — Key:Value Pairs

student = {"name": "Ravi", "age": 21, "course": "CS"}


print(student["name"]) # Ravi
student["age"] = 22 # update value

f) Sets — Unordered, Unique Elements

nums = {1, 2, 2, 3, 3, 3}
print(nums) # {1, 2, 3} (duplicates removed automatically)

Quick Comparison: | Feature | List [] | Tuple () | Dict {k:v} | Set {} | |---------|-----------|------------|---------------|-----------| | Ordered | Yes |
Yes | Yes (3.7+) | No | | Mutable | Yes | No | Yes | Yes | | Duplicates | Allowed | Allowed | Keys unique | Not allowed |

5. Operators in Python

a) Arithmetic Operators

Operator Meaning Example ( a=10, b=3 ) Result

+ Addition a + b 13

- Subtraction a - b 7

* Multiplication a * b 30

/ Division (float) a / b 3.333

// Floor Division a // b 3

% Modulus (remainder) a % b 1

** Exponent a ** b 1000

b) Comparison Operators
Operator Meaning Example Result

== Equal to 5 == 5 True

!= Not equal 5 != 3 True

> Greater than 5 > 3 True

< Less than 5 < 3 False

>= Greater/equal 5 >= 5 True

<= Less/equal 5 <= 4 False

c) Logical Operators

a = True
b = False
print(a and b) # False — both must be True
print(a or b) # True — at least one True
print(not a) # False — reverses value

d) Bitwise Operators (operate on binary bits)

Operator Meaning Example ( a=5=0101, b=3=0011 ) Result

& AND a & b 1

\| OR a \| b 7

^ XOR a ^ b 6

~ NOT ~a -6

<< Left Shift a << 1 10

>> Right Shift a >> 1 2

e) Membership Operators

fruits = ["apple", "banana"]


print("apple" in fruits) # True
print("mango" not in fruits) # True

f) Identity Operators

a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a is c) # True (same object in memory)
print(a is b) # False (different objects, same values)
print(a == b) # True (values are equal)

6. Taking User Input & Type Conversion

User Input

input() always returns a string, regardless of what the user types.

name = input("Enter your name: ")


age = input("Enter your age: ") # returned as string, e.g. "20"

Type Conversion
Function Converts to Example

int() Integer int("20") → 20

float() Float float("5.5") → 5.5

str() String str(20) → "20"

bool() Boolean bool(0) → False

age = int(input("Enter your age: ")) # convert string input to int


print(age + 5) # now works as a number

7. Basic I/O Operations

Output — print()

print("Hello, World!")
name = "Sam"
print("Hello,", name) # Hello, Sam
print(f"Hello, {name}!") # f-string (recommended)
print("A", "B", "C", sep="-") # A-B-C
print("No newline", end=" ") # controls line ending

Input — input()

city = input("Which city do you live in? ")


print("You live in", city)

Mini Example — Combining Everything

name = input("Enter your name: ")


age = int(input("Enter your age: "))

if age >= 18:


print(f"Hi {name}, you are an adult.")
else:
print(f"Hi {name}, you are a minor.")

Quick Recap Summary

Python = simple, readable, interpreted, versatile language created by Guido van Rossum
Variables need no type declaration; keywords are reserved words
6 core data types: int , float , str , list , tuple , dict , set
Operators: Arithmetic, Comparison, Logical, Bitwise, Membership, Identity
input() → always string → use int() / float() to convert
print() is the main way to display output

You might also like