r/learnpython • • 19h ago

The python library "Beautiful Soup", from where did it gets that name from?

33 Upvotes

√|


r/learnpython • • 16h ago

Is it normal in an interview for an interviewer to ask very niche questions?

61 Upvotes

I recently had an interview for an intern position. my resume had some good Python projects and my previous internship experience also involved Python.

The interviewer began by asking me basic Python questions, which I answered well. He then moved on to more detailed questions.

Interviewer: What would be the output of the following code?


num1 = 1

num2 = 1

num3 = 257

num4 = 257

print(num1 is num2, num3 is num4)

I know about integer caching in python, so I said True, False. The interviewer asked if I was sure, and I said yes. He then handed me his laptop, opened VS Code, and asked me to run the code. To my horror, it printed True, True.

He moved on to the next question.

Interviewer: What is __init__ in Python?

Me: It’s a constructor for a class.

Interviewer: What is the first argument it takes?

Me: The object we created.

Interviewer: If it’s the constructor, how can it take the object itself? Who creates the object if __init__ is the constructor?

Me : Silence.

I know it's kinda my fault for this question.

Moved on to the next question

Interviewer: What is the output of the following code?


def fun(a=[], i=1):

    a.append(i)

    print(a)

fun()

fun(i=2)

I didn’t know that Python reuses the same list when it’s used as a default argument, so I got it wrong.

He moved on to the next question.

Interviewer: What is the output of this code?


tup = ([1, 2, 3], 4, 5)

try:

    tup[0] += [4, 5]

    print('tup modified', tup)

except:

    print('Not modified', tup)

Apparently it raises an error on the third line, but the list still gets modified. The output is:


Not modified ([1, 2, 3, 4, 5], 4, 5)

I haven’t heard back yet, but I’m wondering: is this how python specific interviews typically go?

How should I prepare for these kinds of scenarios next time?


r/learnpython • • 7h ago

My first complete comand in Python, from my first day on:

18 Upvotes

Look:

import random
import time

def drawn(a, b):
    return random.randint(a, b)
answer = 'yes'

while answer == 'yes':
    a = int(input('Min number: '))
    b = int(input('Max number: '))
    print(f'Drawn: {drawn(a, b)}')

    time.sleep(2)

    answer = input('Try again? ').lower()

This creates a random number generator where you can choose the minimum and maximum numbers!


r/learnpython • • 12h ago

Help a beginner out with tuple unpacking :D

1 Upvotes

Yes I know its rather beginner, but since starting my python class I've been breezing through and its been so fun to learn, and I began to wonder why so many pythonists and other high level language users say its so hard.

Then I met tuple unpacking. I don't know what it is or why but its so hard for me to grasp and do. Here's an example problem I struggled with:

Q: analyze daily revenue based on the meals customers purchase

menu = {

"Burger": 12.50,

"Pizza": 15.00,

"Pasta": 13.50,

"Salad": 9.00,

"Sandwich": 8.50,

"Fries": 4.00

}

orders = [

("Monday", "Burger", 2), ---- These are Day, Product, Quantity btw

("Monday", "Pizza", 1),

("Tuesday", "Pasta", 3),

("Wednesday", "Burger", 1),

("Wednesday", "Fries", 4),

("Thursday", "Pizza", 2),

("Friday", "Sandwich", 2),

("Saturday", "Pasta", 2),

("Sunday", "Salad", 3)

]

Basically I'm supposed to get the price from the dictionary, and add to orders to get the daily revenue, such as like

Monday: 40.00
Tuesday: 40.5

and etc

But I keep messing up, I just can't seem to grasp the concept despite how much I have GPT give me more problems, the closest I got was this. One recurring issue I have is making sure a day doesn't repeat, like having Multiple Mondays when it should just be one monday and the final revenue for that day:

def calculate(sales):

daily_sales = {}

for day, product, quantity in orders:

price = menu[product]

daily_sales[day] = daily_sales.get(day, 0) + (price * quantity)

return(daily_sales)

print(orders)


r/learnpython • • 19h ago

Looking for a developer to run my bot on my servers hourly is 10/ usd

0 Upvotes

Looking for a developer to run my bot on my servers hourly is 10/ usd