DAY:05
Q: what is PEP8?
# PEP8 is a python enterprise protocol.
# it means A document that provide guidelines and best pratices on how to write python code..........
# Esko 2001 me sir Guido ben rossum ne lekha tha
# Naming convention ko solve krne keliye .
# jb bhi koi module import kre than uska name builtin module nhi hona cheia.
yani yah bateta hai python ke unnder keseacche thrah se coding kre taki koi problem ya name conflict na occure ho.
DAY:06
Q:What is walrus operator in programming?
Ans: Walrus operator(:=) is a type of operator jo ki multiple line code ko minimumline me lekh kr de deta hai.
eg:-
a=100
print(a+1)
# Same code with helpof walrous operator
print((a:=100)+1) # Eska bhi output 101 aayega
# pratics on array type questions
data=[10,20,30,40,50,60,70]
n=len(data)
i=0
while(i<n):
print(data[i])
i=i+1
# now using walrous operator
data=[10,20,30,40,50,60,70]
i=-1
while(i:=i+1)<(n:=len(data)):
print(data[i])
# next pratices.
ans=input("Do you want to continue(y/n):").lower()
while (ans=='y'):
print("process the request")
# using walrous
while(ans:=input("Do you want to continue(y/n):").lower()=='y'):
print('process the continue')
#Note: Esme jo phle se hai uske asthan pr same type wale ko paste kr de rhe hai aur saath saath warlson operator ka symbol bhi lga de rhe hai.
DAY:07
Q: Differance between list and tuple.
Ans:-
Lists and tuples are both data structures in Python that can store collections of items. However, they have some key differences:
1. **Mutability**:
- **List**: Lists are mutable, meaning you can modify their contents (add, remove, or change items).yani list ke under ke value ko change kr skte hai.
- **Tuple**: Tuples are immutable, meaning once a tuple is created, you cannot modify its contents.eske under ki value ko change nhi kr skte hai.
2. **Syntax**:
- **List**: Lists are defined using square brackets `[ ]`.
```python
my_list = [1, 2, 3]
```
- **Tuple**: Tuples are defined using parentheses `( )`.
```python
my_tuple = (1, 2, 3)
```
3. **Performance**:
- **List**: Lists have a higher overhead due to their mutability and the need to manage dynamic memory allocation. They are generally slower compared to tuples.
- **Tuple**: Tuples are faster and more memory efficient because they are immutable and have a fixed size.
4. **Use Case**:
- **List**: Use lists when you need a collection of items that may change throughout the program (e.g., adding/removing elements).
- **Tuple**: Use tuples when you need a collection of items that should not change (e.g., coordinates, fixed sets of values).
5. **Functions and Methods**:
- **List**: Lists have various methods available to modify their contents, such as `append()`, `remove()`, `sort()`, etc.
- **Tuple**: Tuples have fewer methods since they do not support modification. They mostly support methods that do not change the content, such as `count()` and `index()`.
6. **Slicing and Indexing**:
- Both lists and tuples support slicing and indexing to access elements.
7. **Packing and Unpacking**:
- Both lists and tuples can be used for packing and unpacking values.
Example of packing and unpacking:
```python
# List packing and unpacking
a, b, c = [1, 2, 3]
my_list = [a, b, c]
# Tuple packing and unpacking
x, y, z = (4, 5, 6)
my_tuple = (x, y, z)
```
In summary:
- Use lists when you need a dynamic, modifiable collection of items.
- Use tuples when you need a fixed, unchangeable collection of items.
Q:Why we use list?why we use tuple? and when?
Ans:- Jb data ya values ko change krna ho to hum list use krte hai kyuki esme changing ho skta hai
Jb data change krne ki jarurat na ho to hum tuple use krte hai kyuki yah bhout km memory letahai as acompare to list.aur esme channging process nhi hai .
DAY:08
Q Some logical questions for placement..........
input:-"sky is blue"
output:-"blue is sky"
Ans:-
str1="sky is blue"
my_list=str1.split()# spliting based on white space.jesce sabhi words space k saath alag ho jyenge.'sky','is','blue'
#now reverse the string
my_list=my_list[::-1]# slicing ka use krke reverse kr rhe hai.
# now join based on white space or space" "
str2=" ".join(my_list)
print(str2)
Q2: List=[1,2,2,3,3,4,5,5,5,6,6]
output:-[1,4]
Ans;
list=[1,2,2,3,3,4,5,5,5,6,6]
Comments