Skip to main content
Image

r/learnpython


When should you use requests.Session() instead of requests.get() / requests.post()?
When should you use requests.Session() instead of requests.get() / requests.post()?

I'm learning Python and recently started using requests.Session() in API projects. I understand that it can persist things like headers, cookies, and connections, but I'm curious about how experienced Python developers decide when a Session is actually worth using.

Do you use Session() by default for projects involving multiple requests, or only when you specifically need persistent state?


Advertisement: Just wanted to jump on here and say a huge thank you to all of you

Last year I built a little site (StopOverpaying.org) you can use to see if you're getting overcharged on car insurance (without any spam calls/texts). I posted it on here and you guys almost blew up my site.

Somehow we just hit 700k users (it's now my full-time job), I am SO so grateful to all of you

A few results people sent in:

  • J.S. saved $1,200/year

  • Mike M. saved $2,300/year

  • Larry D. saved $560/year

  • D.S. saved $1,000/year

It doesn't work for everyone, obv, but Consumer Reports says the average person who switches saves $461/year - probably worth a look before your policy renews.

https://stopoverpaying.org

(no spam calls or texts, we don't even have a phone or email list)

Seriously, thank you. I did not expect this many people to care about my weird little insurance project.


How does the 'for' loop work?
How does the 'for' loop work?
words = ['sky', 'apple', 'rhythm', 'fly', 'orange']

for word in words:
    for letter in word:
        if letter.lower() in 'aeiou':
            print(f"'{word}' contains the vowel '{letter}'")
            break
    else:
        print(f"'{word}' has no vowels")

I am trying to learn to code, and I am, at the moment, looking at loops. I am a bit confused on how this loop was able to function, though, as there is no variable for letter or word, so how would Python know what it is? In addition, how does the code, like, function? Does it look at each word individually? Again, the second part of the code states:

 if letter.lower() in 'aeiou':
            print(f"'{word}' contains the vowel '{letter}'")
            break

We haven't given a value for letter?

Lastly, how would the code know what to print? in the first phrase:

            print(f"'{word}' contains the vowel '{letter}'")
            break

Is it going to state all the words with the given value 5 times?

Sorry, as I have asked quite a few questions, and thank you in advance.


I finished Helsinki's Advanced Programming course and would like to know what some popular courses are that could come after this one. Perhaps about DSA or other.
I finished Helsinki's Advanced Programming course and would like to know what some popular courses are that could come after this one. Perhaps about DSA or other.

I like the structure that the MOOC provided and that it teaches a bit about how computers operate. I know that people say "escape tutorial hell as soon as possible", but to me a MOOC is not a tutorial. It's a college level course. If anyone knows of some quality MOOCs that would be a good next step from Helsinki's course please share:).

Also, I have an account with CodeWars and it's a good platform for practicing skills and getting challenges, but it lacks the teaching component. I also try to read books about programming and computers, but it's nice to have something all inclusive like a MOOC.

Thank you for reading.