Python Beginner Tutorial 9 For Absolute Beginners - (Range)

preview_player
Показать описание

📣 Other Social:
Рекомендации по теме
Комментарии
Автор

Dude, I'm a beginner and all this is super new to me. Thanks for taking your time to upload these vids. They are helping me to understand more or less the programming stuff. Keep up the good work Chris.

lilyzarate
Автор

As sowmith gantla said, there's no relationship between that list and the for loop. This confused me initially as I couldn't see how the loop was connecting to the list. You can leave that list out completely and get the exact same results.

From what I can see range() is a counting function that has up to 3 arguments:
1: range(7) will count from zero to the last integer before 7, so the for loop outputs 0 through 6
2: range(3, 7) starts at the first number and ends before the second, so output is 3 through 6
3: range(3, 7, 2) starts at the first and counts up to the second by increments of 2, so output is 3 and 5.

PerryAhern
Автор

The range(1, 5) representing [1, 2, 3, 4] is mainly to make it in line with how things are done in other languages and to make sure the indices makes sense when using array slicing because array indices start at 0, not 1. "for i in range(5)" is the same as "for i in range(0, 5)" and will do 5 iterations. This can easily be mentally mapped to "for(int i = 0; i < 5; i++)". Python have borrowed a lot of things from other languages :)

SuperGrimmy
Автор

my_list has nothing to do with for loop there is no connection.
someone with no prior knowledge of programming language cant understand whats going on in the program.
It would be better to use print(my_list[x]) instead of print(x) and use some names in the list.

sowmithgantla
Автор

thx dude :) I am in a programming school and your videos really helped me haha

hdfman
Автор

And found this one ;)

for i in range(99, 0, -1):
if i == 1:
print('1 bottle of beer on the wall, 1 bottle of beer!')
print('So take it down, pass it around, no more bottles of beer on the wall!')
elif i == 2:
print('2 more bottles of beer on the wall, 2 more bottles of beer!')
print('So take one down, pass it around, 1 more bottle of beer on the wall!')
else:
print('{0} bottles of beer on the wall, {0} bottles of beer!'.format(i))
print('So take it down, pass it around, {0} more bottles of beer on the wall!'.format(i - 1))

cezarysturgulewski
Автор

In python2, range created a actual list in memory while xrange created a generator. In python3 they deleted range and renamed xrange to range. They only kept the generator version. You can see that in interactive mode when doing a "my_list = range(10)". Printing my_list just outputs the string "range(10)". To make an actual list you have to pass the range generator object into the list() constructor. A lot of things in python3 is like that. They made everything into generators to make it faster and less memory-hogging.

SuperGrimmy
Автор

what if there are multiple list, can we still directly use the command range??

jaskoh
Автор

How does the for loop know it's picking up elements from my_list??

tambolaking
Автор

Was the inclusion of the list just a visual example to show how indexing works?

nullhypothesis
Автор

do the values in "range" have to be numbers even if the values in the list are words?

kevinaviles
Автор

Actually the things that you have told in this video is ok but it don't have any connection to our list that we have defined so we have to take loop variable as a index in out list then it will print the exact solution that we want. like my_list[x]

Ravithezealous
Автор

my_list = ['one', 'two', 'three', 'four', 'five']
my_list_len = len(my_list)
for x in range(0, my_list_len):
print(my_list[x])

cezarysturgulewski
Автор

I can't place breakpoints as of recently. They don't appear or get placed when I hover my mouse or click over the breakpoint margin.
In the bottom of the debug window, in the section titled 'breakpoints' there are two options:
- All exceptions &
- Uncaught exceptions
I remember there being a third option but this is no longer there. I think this is the reason for me not being able to place breakpoints anymore. If anyone has any idea how to restore this, advice would be much appreciated :)

mutantmamoth
Автор

hey chirs i used the same code showen in the video but my list had value like [5, 3, 4, 9] still my output was from range 1 to 4 that is
1
2
3
4

prajyotkavalekar
Автор

lol im not a beginner so i know all of this but before i studied and when I tryed to make a project i did not understand

OwlTheMoon
Автор

if you want to go to 10 do I have to type 11. yep it work even I don't have my_list = to 11 just 10

allenofblacksteel