0% found this document useful (0 votes)
0 views

Python Day 1 Training Notes

The document outlines a Day 1 curriculum for Java developers transitioning to Python, covering topics such as Python's features, environment setup, syntax fundamentals, control flow, and functions. It highlights key differences between Java and Python, including dynamic vs. static typing and built-in data structures. Additionally, it includes coding exercises and recommended resources for further learning.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Python Day 1 Training Notes

The document outlines a Day 1 curriculum for Java developers transitioning to Python, covering topics such as Python's features, environment setup, syntax fundamentals, control flow, and functions. It highlights key differences between Java and Python, including dynamic vs. static typing and built-in data structures. Additionally, it includes coding exercises and recommended resources for further learning.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python for Java Developers: Day 1

Introduction to Python (90 minutes)


1. Introduction (10 minutes)
What is Python?
High-level, interpreted programming language
Emphasizes code readability with significant whitespace
Dynamic typing vs Java's static typing
"Batteries included" philosophy with rich standard library
Why Python for AI/ML?
Extensive libraries (NumPy, Pandas, scikit-learn, TensorFlow, PyTorch)
Easy prototyping and readability
Large community support
Integration capabilities
2. Setting Up Python Environment (15 minutes)
Installation & Setup
Python 3.x installation (latest stable version recommended)
Package managers: pip vs Java's Maven/Gradle
Virtual environments: venv (Python's isolation equivalent to Java's classpath)
IDE options
PyCharm (full IDE similar to IntelliJ IDEA)
VS Code with Python extensions
Jupyter Notebooks for interactive development (excellent for ML)
First Python program
python

# This is a comment
print("Hello, Python!")

3. Python Syntax Fundamentals (25 minutes)


Indentation vs Braces
Python uses indentation for code blocks (typically 4 spaces)
No curly braces or semicolons
python

# Java style:
# if (condition) {
# System.out.println("True");
# }

# Python style:
if condition:
print("True")

Variables and Data Types


Dynamic typing (no type declarations needed)
Common types: int, float, str, bool, list, tuple, dict, set
Type hints (optional, similar to Java generics)
python

# Dynamic typing
x = 10 # int
x = "hello" # now a string
x = 3.14 # now a float

# Type hints (Python 3.5+)


def greet(name: str) -> str:
return f"Hello, {name}!"

Basic Data Structures


Lists (similar to ArrayList in Java)
Tuples (immutable lists)
Dictionaries (similar to HashMap)
Sets (similar to HashSet)
python

# List (mutable)
my_list = [1, 2, 3, "four", 5.0]
my_list.append(6)
print(my_list[0]) # Access by index: 1

# Tuple (immutable)
my_tuple = (1, 2, "three")

# Dictionary (key-value pairs)


my_dict = {"name": "John", "age": 30}
print(my_dict["name"]) # Access by key: John

# Set (unique values)


my_set = {1, 2, 3, 3} # Stored as {1, 2, 3}

4. Control Flow (15 minutes)


Conditionals
if, elif, else (vs Java's if, else if, else)
No parentheses required around conditions
python

age = 18
if age < 18:
print("Minor")
elif age == 18:
print("Just turned adult")
else:
print("Adult")

Loops
for loops with in keyword (different from Java's C-style for)
while loops
List comprehensions (unique to Python)
python

# For loop with range


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

# Iterating through a list


animals = ["dog", "cat", "bird"]
for animal in animals:
print(animal)

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

# List comprehension (create a new list with a one-liner)


squares = [x**2 for x in range(10)] # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

5. Functions (15 minutes)


Defining and Calling Functions
def keyword (vs Java's access modifiers and return types)

Default parameters
Variable arguments with *args and **kwargs
python

# Basic function
def greet(name):
return f"Hello, {name}!"

# Function with default parameter


def greet_with_title(name, title="Mr."):
return f"Hello, {title} {name}!"

print(greet("John")) # Hello, John!


print(greet_with_title("John")) # Hello, Mr. John!
print(greet_with_title("Jane", "Ms.")) # Hello, Ms. Jane!

# Variable arguments
def sum_all(*numbers):
return sum(numbers)

print(sum_all(1, 2, 3, 4)) # 10

# Keyword arguments
def build_profile(**user_info):
return user_info

profile = build_profile(name="John", age=30, job="Developer")


print(profile) # {'name': 'John', 'age': 30, 'job': 'Developer'}

6. Coding Exercise (10 minutes)


Task: Write a function that takes a list of numbers and returns a dictionary with the count of even
and odd numbers.
Solution:
python

def count_even_odd(numbers):
result = {"even": 0, "odd": 0}

for num in numbers:


if num % 2 == 0:
result["even"] += 1
else:
result["odd"] += 1

return result

# Test the function


numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(count_even_odd(numbers)) # {'even': 4, 'odd': 5}

Key Java vs Python Differences to Highlight:


1. Syntax: Indentation vs. braces and semicolons
2. Dynamic typing vs. static typing
3. Built-in data structures (lists, dictionaries) vs. Java collections
4. Simplicity of Python functions vs. Java methods
5. Python's "one obvious way" vs. Java's multiple approaches
Homework/Practice:
1. Write a function that converts temperatures between Celsius and Fahrenheit
2. Create a program that counts word frequencies in a given string
3. Implement a simple calculator that performs basic operations (+, -, *, /)
Recommended Resources:
Official Python Documentation: https://docs.python.org/3/
"Automate the Boring Stuff with Python" by Al Sweigart
Python for Java Developers: https://realpython.com/java-vs-python/

You might also like