Essentials_of_Python_Unit1_Notes (2)
Essentials_of_Python_Unit1_Notes (2)
Introduction
- Why Python?
- Python Installation
- Basic Elements
- String Operations: Concatenation (+), Slicing ([:]), Methods (.upper(), .lower(), etc.)
- Output Formatting
name = "Priyanshu"
print(f"Hello {name}")
print("Hello {}".format(name))
- Operators
if condition:
# code
elif condition:
# code
else:
# code
- Loops
while loop
- range() Syntax
- Assert
- Loop Example
for i in range(5):
print(i)
- Defining a Function
def greet():
print("Hello")
- Function Documentation
def func():
'''This is a docstring'''
pass
- Lambda Functions
- map() Function
result = list(map(lambda x: x+2, [1, 2, 3]))
- Modules
Importing modules:
import math
print(math.sqrt(16))