DONT Make This Python Mistake!! #python #programming #coding

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

Background Music:
Creative Commons / Attribution 4.0 International (CC BY 4.0)
Рекомендации по теме
Комментарии
Автор

If you just need to print the list, you can actually do so without even writing a for loop. Just using the args operator and sep parameter in print:
print(*inv, sep=“\n”)

AWriterWandering
Автор

Additionally you can choose starting index by adding 'start = (int)' keyword argument 😊

nemo
Автор

These vids are sooo legit. Great stuff.

chacho
Автор

I finally now understand enumerate()

Thank you so much.

caspermoon
Автор

oh damn, you have no idea how many times this would have come in clutch for me!

nobodyofconsequence
Автор

Using i and length is required when you want to change the length of the list, as you can't do that with the i in list

dany_fg
Автор

I know it's a small thing in programming overall but I love python for loops. Super easy, Super clean, super readable, super duper

sadhappy
Автор

Another thing to add to the enumerate function, if the second iterator name is insignificant and is only used for the index - like in the video - you can use syntax such as “for i, _ in enumerate(…”

fabriziolyles
Автор

that's really a valuable infotrmation

eslamhemdan-if
Автор

I wouldn't call it index as that is a built in method in python that you will overwrite and no longer be able to use. idx is usually my goto, i works as well

alfarisw
Автор

Well as a python beginner I always used for loops to print lists and probably still will

proheroexperiencing
Автор

Yes, it has a cleaner code if use the enumerate function, but if you don't need to use index elsewhere and the length of list is huge then you actually need to iterate the list twice which gives a lower efficiency.

Goodman._
Автор

People that write syntax with that Range() in the former example is almost guaranteed to be people from other programming language. Probably one with C Programming language base, where for loops via index was taught first as opposed to Python language that use foreach loop first

RobertGuilman
Автор

He don't need keyboard i just writing with his mouse

thehelper
Автор

Another thing to consider, if you assign "index" as a variable, it'll override the built-in index method, so later on in the function, you won't be able to use it.

fusionfuryx
Автор

And if you do not like it when it starts at 0. Just add start=1 in the enumerate after list variable

Like:
junk = ['a', 'b', 'iPhone', 'Samsung']

for index, item in enumerate(junk, start=1):
print(f"[{index}] - {item}")

fluffyflextail
Автор

I like python bcs you can use for almost anything but at the same time hate it because there are too many ways of making the same thing. I stay with C++ ❤

MrShaquille
Автор

Time complexity is o(n) in both cases. However, enumerate is a magic in py.

rayroy
Автор

what theme/font do you use?? i'm in love with the way your shorts look lol

ashie.official
Автор

Tbh i never did the wrong example one coz dang it looks more confusing to me😅

mjdevlog