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

Week 1

The document provides detailed notes and practice problems for Week 1 of a Python course, covering fundamentals such as Python basics, tools like Google Colab and Replit, data types, operators, and string manipulation. It includes practical examples and exercises to reinforce learning, such as variable assignments, user input, and string operations. The content is structured to align with the course topics, ensuring a comprehensive understanding of Python fundamentals.
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)
15 views5 pages

Week 1

The document provides detailed notes and practice problems for Week 1 of a Python course, covering fundamentals such as Python basics, tools like Google Colab and Replit, data types, operators, and string manipulation. It includes practical examples and exercises to reinforce learning, such as variable assignments, user input, and string operations. The content is structured to align with the course topics, ensuring a comprehensive understanding of Python fundamentals.
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/ 5

Detailed Notes and Practice Solutions

Detailed Notes and Practice Solutions


Below are detailed notes and solved practice problems based on the provided course structure.
Each section corresponds to the topics listed in the course.

Week 1: Python Fundamentals

1. Orientation of the Course


The course introduces Python basics, tools, and platforms like Google Colab and Replit for
coding.
Tools like Python Tutor help visualize code execution step-by-step.

2. Introduction to Tools

Google Colab
A cloud-based platform for writing and executing Python code.
Supports GPU/TPU for resource-intensive tasks.
Use Runtime -> Change Runtime Type to switch to GPU/TPU [1] .

Replit
A browser-based IDE for coding collaboratively.
Features include real-time previews, AI-assisted debugging, and GitHub integration [2] .

3. Python Basics

Variables and Literals


Variables store data values. Examples:
x = 5 # Integer
y = 3.14 # Float
z = "Hello" # String
Literals are fixed values like numbers (e.g., 10) or strings (e.g., "Python") [3] .

Input Statements
Use input() to take user input:
name = input("Enter your name: ")
print("Hello", name)

Data Types
Common data types in Python:
Data Type Example

int x = 10

float x = 3.14

str x = "Hello"

list x =[^1][^2][^3]

tuple x = (1, 2, 3)

dict x = {"a":1} [4] [5] .

4. Operators and Expressions

Arithmetic Operators
Perform mathematical operations:
a, b = 5, 2
print(a + b) # Addition
print(a - b) # Subtraction
print(a * b) # Multiplication
print(a / b) # Division
print(a % b) # Modulus

Comparison Operators
Compare values:
print(5 > 3) # True
print(5 == 3) # False
Logical Operators
Combine conditions:
print(True and False) # False
print(True or False) # True

String Operations
Concatenation: "Hello" + " World"

Repetition: "Hi" * 3 → "HiHiHi" [6] .

5. Strings

Indexing and Slicing


Access specific characters or substrings:
s = "Python"
print(s[^0]) # 'P'
print(s[-1]) # 'n'
print(s[1:4]) # 'yth'

Common String Methods


.upper(), .lower(), .replace(), .strip().

Practice Problems with Solutions

Problem Set: Variables and Input Statements


1. Assign multiple variables in one line:

a, b, c = "Apple", "Banana", "Cherry"


print(a, b, c)

2. Take user input:

name = input("What is your name? ")


print(f"Welcome, {name}!")
Problem Set: Data Types
1. Identify data types:

x = [1, "two", True]


for item in x:
print(type(item))

Output:

<class 'int'>
<class 'str'>
<class 'bool'>

2. Create a dictionary:

person = {"name": "John", "age": 30}


print(person["name"])

Problem Set: Operators


1. Arithmetic Operations Practice:

a, b = map(int, input("Enter two numbers: ").split())


print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)

2. Logical Expression Evaluation:

x = True
y = False
print(x or y) # True
print(x and y) # False

Problem Set: Strings


1. Reverse a string:

s = "Python"
print(s[::-1]) # Output: nohtyP

2. Count character frequency in a string:


from collections import Counter

s = "google.com"
freq = Counter(s)
print(freq)

Output:
{'g':2, 'o':3, 'l':1, 'e':1, '.':1, 'c':1, 'm':1}

Problem Set: Indexing and Slicing


1. Extract specific letters from the alphabet using slicing:

from string import ascii_uppercase

# Every fourth letter:


print(ascii_uppercase[::4]) # AEIMQUY

# Reverse alphabet:
print(ascii_uppercase[::-1]) # ZYXWVUTSRQPONMLKJIHGFEDCBA

2. Extract substring from a sentence:

sentence = "We are learning Python programming."


print(sentence[11:19]) # Output: Python p

These notes and practice problems cover all the essential concepts from Week 1 of your course
structure.

1. https://www.marqo.ai/blog/getting-started-with-google-colab-a-beginners-guide
2. https://docs.replit.com/getting-started/intro-replit
3. https://www.programiz.com/python-programming/variables-constants-literals
4. https://pynative.com/python-data-types/
5. https://www.w3schools.com/python/python_datatypes.asp
6. https://realpython.com/python-operators-expressions/

You might also like