0% found this document useful (0 votes)
4 views7 pages

Python Intro Module1, 2

The document provides comprehensive notes on Python programming, covering topics such as the importance of programming, computer hardware architecture, basic programming concepts, and Python syntax. It includes sections on conditional execution, functions, error handling, and debugging techniques. Key concepts emphasize problem-solving strategies and the organization of code for better readability and maintainability.

Uploaded by

atakatarun
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)
4 views7 pages

Python Intro Module1, 2

The document provides comprehensive notes on Python programming, covering topics such as the importance of programming, computer hardware architecture, basic programming concepts, and Python syntax. It includes sections on conditional execution, functions, error handling, and debugging techniques. Key concepts emphasize problem-solving strategies and the organization of code for better readability and maintainability.

Uploaded by

atakatarun
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

Python Programming - Complete Course Notes

Module 1: Introduction to Python Programming

1.1 Why Learn Programming?

Creative and Rewarding Activity: Programming allows you to build useful, elegant, and clever
programs.

Motivations: - Problem-solving for data analysis - Career opportunities (financially and personally
rewarding) - Helping others solve problems - Personal productivity in handling data

1.2 Computer Hardware Architecture

Core Components: - Central Processing Unit (CPU): Executes instructions; measured in GHz (billions
of operations per second). - Main Memory (RAM): Fast, temporary storage for active data; volatile (data
lost when power is off). - Secondary Memory: Permanent storage like hard drives or flash memory;
non-volatile. - Input/Output Devices: Keyboard, mouse, monitor, speaker, etc. - Network Connection:
Allows remote data transfer, often slower and less reliable.

1.3 Understanding Programming

Two Essential Skills: 1. Programming Language Knowledge: Vocabulary and syntax of Python. 2.
Problem-Solving Ability: Logical combination of instructions to achieve results.

Key Concepts: - Python has a small set of reserved words. - Variables are user-defined names for data. -
Programs are sequences of instructions that solve problems.

1.4 Getting Started with Python

Interactive Mode:

>>> print("Hello world!")


Hello world!

Running Scripts: Create a file [Link] :

print('Hello world!')

Run with: python [Link]

1
1.5 Programming Terminology

• Interpreter: Executes code line-by-line (Python uses this).


• Compiler: Translates entire code before execution.
• High-Level Language: Human-readable programming languages (Python, C++, Java).
• Machine Language: Binary code understood by CPU.

1.6 Basic Building Blocks

• Input: Getting data from user or files.


• Output: Displaying results.
• Sequential Execution: Steps run in order.
• Conditional Execution: Executes code based on condition.
• Repeated Execution: Loops for repeated actions.
• Abstraction: Combining code into reusable functions.

1.7 Common Error Types

• Syntax Errors: Grammar mistakes in Python.


• Logic Errors: Wrong statement order.
• Semantic Errors: Code runs but gives wrong output.

1.8 Variables, Values and Types

Basic Data Types: - int: Integer numbers (2, -5) - float: Decimal numbers (3.14, -2.5) - str: String of
characters ('Hello')

Variable Assignment:

message = 'And now for something completely different'


n = 17
pi = 3.141592653589793

Variable Naming Rules: - Must contain letters, numbers, or underscores. - Cannot start with a number.
- Case-sensitive. - Cannot use keywords. - Use meaningful names.

1.9 Expressions and Operators

Arithmetic Operators:

20 + 32 # Addition
hour - 1 # Subtraction
hour * 60 # Multiplication

2
minute / 60 # Division
5 ** 2 # Exponentiation

Order of Operations (PEMDAS): Parentheses → Exponentiation → Multiplication/Division → Addition/


Subtraction.

Modulus Operator:

quotient = 7 // 3 # Integer division → 2


remainder = 7 % 3 # Modulus → 1

String Operations:

first = '100'
second = '150'
print(first + second) # '100150'

1.10 User Input and Comments

Getting Input:

inp = input('Enter Fahrenheit Temperature: ')

Adding Comments:

# Compute percentage of hour that has elapsed


percentage = (minute * 100) / 60 # Everything after # is ignored

1.11 Debugging Basics

• Syntax Errors: Illegal variable names, missing operators.


• Runtime Errors: Occur during program execution.
• Semantic Errors: Wrong logic or order of operations.

Module 2: Conditional Execution and Functions

2.1 Boolean Expressions and Operators

Boolean Values:

3
>>> 5 == 5
True
>>> 5 == 6
False
>>> type(True)
<class 'bool'>

Comparison Operators: == , != , > , < , >= , <=

Logical Operators: and , or , not

2.2 Conditional Statements

Simple if Statement:

if x > 0:
print('x is positive')

Alternative Execution (if-else):

if x % 2 == 0:
print('x is even')
else:
print('x is odd')

Chained Conditionals (if-elif-else):

if x < y:
print('x is less than y')
elif x > y:
print('x is greater than y')
else:
print('x and y are equal')

Nested Conditionals:

if x == y:
print('x and y are equal')
else:
if x < y:
print('x is less than y')
else:
print('x is greater than y')

4
2.3 Exception Handling

inp = input("Enter Fahrenheit Temperature: ")


try:
fahr = float(inp)
cel = (fahr - 32.0) * 5.0 / 9.0
print(cel)
except:
print('Please enter a number')

2.4 Short-Circuit Evaluation

Python stops evaluating expressions once the outcome is known.

Guardian Pattern: Prevents division by zero.

x >= 2 and y != 0 and (x/y) > 2

2.5 Functions

Built-in Functions: type() , max() , min() , len()

Type Conversion Functions: int() , float() , str()

Math Functions:

import math
[Link](5)
math.log10(100)
[Link](45)

Random Numbers:

import random
[Link]()
[Link]([1, 2, 3])

2.6 Defining New Functions

5
def print_lyrics():
print("I'm a lumberjack, and I'm okay")
print("I sleep all night and I work all day")

Function Calls:

def repeat_lyrics():
print_lyrics()
print_lyrics()

repeat_lyrics()

2.7 Parameters and Arguments

def print_twice(bruce):
print(bruce)
print(bruce)

print_twice('Spam')
print_twice([Link])

2.8 Fruitful vs Void Functions

Fruitful (Return values):

x = [Link](radians)
golden = ([Link](5) + 1) / 2

Void (No return value):

result = print_twice('Bing') # result is None

Creating Fruitful Function:

def addtwo(a, b):


added = a + b
return added

x = addtwo(3, 5) # x becomes 8

6
2.9 Why Use Functions?

• Organization: Improves readability.


• Reusability: Reduces repetition.
• Maintainability: Easy updates.
• Debugging: Test independently.
• Modularity: Portable across programs.

2.10 Debugging Tips

• Tracebacks: Identify error type and location.


• Whitespace Errors: Check indentation.
• Incremental Testing: Test code frequently.
• Error Messages: Indicate where the issue was found, not necessarily where it occurred.

Key Concepts Covered: - Python fundamentals and syntax - Conditional logic and flow control -
Function creation and usage - Error handling techniques - Problem-solving strategies

[Continued in Next Part - Modules 3–5]

DOWNLOAD: Complete Structured Python Notes

You might also like