Python Beginner Notes and Exercises
Python Beginner Notes and Exercises
Examples:
- len("Hello") => 5
- "hello".count("l") => 2
Formatted String:
name = "John"
Examples:
num = 3.14
Arithmetic Operations:
- 3 + 2 => 5
- 3 - 2 => 1
- 3 * 2 => 6
Python Beginner Notes with Examples & Exercises
- 3 / 2 => 1.5
- 3 ** 2 => 9 (exponent)
- 3 % 2 => 1 (modulus)
Useful Functions:
- abs(-5) => 5
- round(3.75) => 4
Lists:
courses.append("Physics")
courses.insert(0, "Biology")
courses.remove("Math")
courses.sort()
courses.reverse()
Tuple:
Set:
No duplicates, unordered
Set Functions:
- intersection()
- difference()
Python Beginner Notes with Examples & Exercises
- union()
4. Exercises
1. Create a string variable called `greeting` with value "Hi There", and print its uppercase version.
3. Create a list of 3 fruits. Add one more fruit and remove the second fruit.
5. Write a formatted string to say "Welcome, Alex!" using variable `name = "Alex"`.