Introduction To Python
Introduction To Python
Indentation-based syntax
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5“)
Variables:
• Variable Assignment
x=5
• Data Manipulation
y=x+3
Control Flow and Loops
Conditional Statements:
if x > 0:
print("Positive")
elif x < 0:
print("Negative")
else:
print("Zero")
Loops:
for i in range(5): while x > 0:
print(i)
print(x)
Functions
Definition using 'def':
def greet(name):
print("Hello, " + name)
Calling a Function:
greet("Alice")
Tuples:
Ordered, Immutable
Example: (1, 2, 3)
Dictionaries:
Unordered, Key-Value Pairs
Example: {'a': 1, 'b': 2}
File Handling
Opening a File:
file = open("example.txt", "r")
Reading from a File:
content = file.read()
Writing to a File:
file = open("example.txt", "w")
file.write("Hello, Python!")
Appending to a File:
file = open("example.txt", "a")
file.write("\nNew content")
Closing a File:
file.close()
Libraries and Frameworks
Python Ecosystem:
• Extensive libraries and
• frameworks
• Examples:
• NumPy: Numerical computing
• Pandas: Data manipulation
• Django: Web development
• Flask: Web microframework
• TensorFlow: Machine Learning
Conclusion
Recap of Key Concepts:
Python syntax, data types,
control flow, functions,
data structures, file handling,
libraries, and frameworks
Python's Strengths:
Versatility, readability,
extensive community support
Encourage Further Learning:
Explore online courses,
documentation, and community
forums for continued learning