Python_Notes_Fixed-1
Python_Notes_Fixed-1
Example:
x = 10
print(x) # Output: 10
2. Arithmetic Operations
3. Type Conversions
int(3.33) -> 3
float(10) -> 10.0
int('100') + 1 -> 101
5. Power Operator
a ** b calculates power.
Example:
a=2
b=3
print(a ** b) # Output: 8
6. Swapping Lists
7. Functions
8. Boolean Values
Example:
def can_run_for_president(age):
return age >= 35
print(can_run_for_president(19)) # Output: False
9. Lists
Lists support slicing and built-in functions like len(), sorted(), sum().
10. Loops
Example:
squares = [n**2 for n in range(10)]
12. Strings
Use escaping characters and string operations like split() and join().
Example:
datestr = '1956-01-31'
year, month, day = datestr.split('-')
13. Dictionaries
Example:
numbers = {'one': 1, 'two': 2, 'three': 3}
print(numbers['one']) # Output: 1