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

Python Class Notes

This document provides an overview of Python programming fundamentals, covering topics such as syntax, variables, data types, control structures, functions, lists, and dictionaries. Key points include Python's dynamic typing, use of indentation, and basic operations. It concludes with a homework assignment to write a program for calculating the factorial of a number using a loop.

Uploaded by

Atul
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 views3 pages

Python Class Notes

This document provides an overview of Python programming fundamentals, covering topics such as syntax, variables, data types, control structures, functions, lists, and dictionaries. Key points include Python's dynamic typing, use of indentation, and basic operations. It concludes with a homework assignment to write a program for calculating the factorial of a number using a loop.

Uploaded by

Atul
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
You are on page 1/ 3

Class Notes: Fundamentals of Python

Programming

1 Introduction to Python
Python is a high-level, interpreted programming language known for its read-
ability and versatility. It is widely used in web development, data science, au-
tomation, and more.

2 Basic Syntax
Python uses indentation to define code blocks, unlike other languages that use
braces or keywords.

2.1 Variables and Data Types


Variables in Python are dynamically typed, meaning you don’t need to declare
their type.
# Examples of variables
name = ”Alice” # String
age = 20 # Integer
height = 5.7 # Float
is_student = True # Boolean

2.2 Basic Operations


• Arithmetic: +, −, ∗, /, //, %, ∗∗

• Comparison: ==, ! =, <, >, <=, >=

• Logical: and, or, not


# Arithmetic example
x = 10
y = 3
print(x + y) # Output: 13
print(x // y) # Output: 3 (floor division)

1
3 Control Structures
Control structures manage the flow of a program.

3.1 Conditionals
age = 18
if age >= 18:
print(”Adult”)
else:
print(”Minor”)

3.2 Loops
• For Loop: Iterates over a sequence.

• While Loop: Repeats as long as a condition is true.


# For loop example
for i in range(5):
print(i) # Outputs: 0, 1, 2, 3, 4

# While loop example


count = 0
while count < 5:
print(count)
count += 1

4 Functions
Functions are defined using the def keyword.
def greet(name):
return f”Hello,␣{name}!”

print(greet(”Alice”)) # Output: Hello, Alice!

5 Lists and Dictionaries


5.1 Lists
Lists are ordered, mutable collections.
fruits = [”apple”, ”banana”, ”cherry”]
fruits.append(”orange”) # Add item
print(fruits[1]) # Output: banana

2
5.2 Dictionaries
Dictionaries store key-value pairs.
student = {”name”: ”Alice”, ”age”: 20}
print(student[”name”]) # Output: Alice
student[”grade”] = ”A” # Add key-value pair

6 Key Points to Remember


• Python is dynamically typed and uses indentation for code blocks.

• Basic data types include integers, floats, strings, and booleans.

• Control structures like conditionals and loops manage program flow.

• Functions, lists, and dictionaries are fundamental for organizing code and
data.

Homework: Write a Python program to calculate the factorial of a number using


a loop.

You might also like