r/learnpython • • Mar 01 '21

Python is kicking my butt

I’ve been learning python since early December now.. I seemed to become comfortable with the syntax and was gaining confidence quickly!

Then I moved on to Django and was quickly sent a reality check as the difficulty level increased really fast... I went back to python and started learning classes... this also is extremely hard to grasp..

While learning classes I realized I didn’t know for loops.. dictionaries.. len/range() nearly as much as I thought I did... the confidence I so quickly built is now gone.

I know the journey to web dev isn’t going to be easy at all.. I’m not giving up.. just wanted to get this off my chest.. I’m going back to the basics this week. Wish me luck. Have a nice week!

486 Upvotes

118 comments sorted by

View all comments

6

u/[deleted] Mar 01 '21

len/range() nearly as much as I thought I did...

I don't really get what you think there is to know about len and range (which are two separate functions that don't really relate to each other except coincidentally.) len is especially simple - it returns the number of values contained in a collection. Easy!

range is a little subtle and its documentation is wrapped up with tuple and list so it's not especially clear:

https://docs.python.org/3/library/stdtypes.html#typesseq

but the long and the short of it is that it's an iterator over sequences of integers, and the most common and easiest to understand way to specify a sequence of integers is as a sequence between 0 and some other value. (For various good but tedious reasons, the interval is specified as half-open, and thus includes zero but not the end term.)

7

u/[deleted] Mar 01 '21

Maybe it's those times when len and range are used together, like

for i in range(len(input_list)):
    pass

2

u/arkie87 Mar 01 '21

Yea, that’s how I understood it as well as that is the major way those functions are related