courseDocs_uqu7onuc
courseDocs_uqu7onuc
What is Python?
Python is a high-level, interpreted programming language known for its simplicity and
readability. It is widely used for various applications, including web development, data analysis,
artificial intelligence, machine learning, and more.
Features of Python
1. Easy to Learn and Use: Python has a simple syntax that resembles natural language,
making it beginner-friendly.
8
2. Interpreted: Python code is executed line by line, which helps in debugging.
3. Platform Independent: Python can run on different operating systems like Windows,
macOS, and Linux.
4. Dynamic Typing: You don’t need to declare variable types; Python assigns them
R
automatically.
5. Extensive Libraries: Python has a rich set of libraries, such as NumPy, Pandas, and
Matplotlib, for various purposes.
6. Object-Oriented: Python supports object-oriented programming, which helps in creating
reusable code.
7. Community Support: Python has a large community for support and resources.
C
Tokens in Python
1. Keywords: Reserved words like if, else, while, def, etc.
2. Identifiers: Names used for variables, functions, or objects.
3. Literals: Fixed values like numbers (10, 3.14) or strings ("Hello").
4. Operators: Symbols like +, -, *, /, etc.
5. Delimiters: Characters like (), {}, [], :, ,, etc.
Data Types in Python
○ set: {1, 2, 3}
8
○ dict: Key-value pairs (e.g., {"key": "value"})
6. Set Types:
Loops in Python
1.for Loop: Iterates over a sequence (e.g., list, range).
python
8
Copy code
for i in range(5):
print(i)
2.while Loop: Repeats as long as a condition is true.
python
Copy code
x=0
R
while x < 5:
print(x)
x += 1
3.break: Exit the loop prematurely.
python
C
Copy code
for i in range(10):
if i == 5:
break
print(i)
4.continue: Skips the current iteration and moves to the next.
python
Copy code
for i in range(5):
if i == 3:
Continue
print(i)
Introduction to Python Libraries
Python libraries are collections of pre-defined code that provide specific functionalities to
simplify complex programming tasks. They allow developers to focus on the core logic rather
than writing common functionalities repeatedly.
●
●
8
Pre-written modules for specific tasks.
Easy to import and use in any Python program.
●
R
Extensive documentation and tutorials available.
● Active support from the Python community.
8. Utility Libraries
8
● OS: Provides functions to interact with the operating system.
● Requests: Simplifies sending HTTP requests to websites.
R
How to Use Python Libraries
1.Import the Library
Use the import keyword to include a library in your program.
import library_name
C
2.Install Missing Libraries
If the library is not installed, use pip to install it.
1.
Benefits of Python Libraries
● Reduces Complexity: Built-in functions reduce the need for writing complex code.
● Speeds Up Development: Pre-tested functions save debugging time.
● Encourages Standardization: Promotes the use of best practices in programming.
● Extensive Ecosystem: Thousands of libraries available for every domain.
8
R
C