explanation: adjacent string literals are implicitly concatenated. on lines 4 and 5, the two strings "three" and "four" are concatenated into "threefour"
@@patloeber s="foo" id(s)=140542718184424 id(s[0])= 140542719027040 id(s[1])= 140542718832152 id(s[2])= 140542718832152 I did not understand how each character is getting stored in memory and and why id of ' s ' is not equal to id of s[0] (like it use to be in c) and why id of s1 and s2 are same? can do a video in this topic
I don't see an issue here. Between "three" and "four" there is no comma, thus concatenating them into one string. This will result in having four strings in the array. This is intended behaviour for very large strings, so that one can break them into multiple lines. Edit: I guess one could say: "It's not a bug. It's a feature. :)"
@@pawelpow I've been employed at a company developing a Python backend for 2 years now and this has never happened to me accidentally. So I think calling it a "serious" issue is a bit too dramatic. I'm not a Python fan though, but for other reasons
@@richardpaulhall no it's not, he didn't put a comma after 3 which concentrated the value to be one as it was never differentiated. Nothing shows it as a bad language here
@@yairkaz However, this python feature may cause some unexpected results when coding a big proyect. Imagine having this problem in thousands lines of code 😖
@@richardpaulhall It's arguable, by the same standard I could point to a hammer a person just used to bang his own finger, and say, "Sorry but that's an example of a bad tool"
If you want to see length of list equal to 5 you need to add a comma after the string « three » Without a final comma, the string « Three » will be a literal that will be concatenated to the string « Four ».
I definitely think this should throw a compile time error. Its strange and unexpected behavior for most devs, even as someone who has been using python exclusively for the last two years, I spotted the missing comma but though its going to throw a syntax error, not implicitly concat them. On the same note, people should watch our for additional commas (not only missing commas) as well as commas are what syntactically create tuples not round brackets. You might mistakenly create tuples if you place a comma by mistake somewhere.
That is because of "string literal concatenation" in python; if you try to write codes in iterables like lists and tuples (or just regular parentheses) with the block structure like in the video and your data type is just string, if you miss comma, SLC whould happen. in the first look SLC maybe seem undesired but it could be usefull sometimes. for example you can split up long lines in two or more between parentheses: print("long line") print("long" "line" ) the output whould be the same but it makes your code cleaner.
God damn it. This is triggering PTSD flashbacks. When missing commas, fullstops, semicolons and typos escape the compiler without errors but breaks days of work...
>>> a = [ ... "one", ... "two", ... "three", ... "four", ... "five" ... ] >>> print(a) ['one', 'two', 'three', 'four', 'five'] >>> len(a) 5 python3 --version Python 3.8.10 mmmh oh, nvm i'm blind. Also gotta agree. The most annoying part of learning any programming language is my brain filtering out vital stuff or doing the good ol' "aww, come on. it's cool. what could go wrong?" .
No it's not a bug it is because the first list item is said to be in index 0, and the second item is said to be in index 1, and third item is index 2. The fourth is 3rd index. The fifth is index 4th
Python is c-like in that it is 0-based indexed. So “one” is 0 and “five” is 4 in memory. So when u print the length (len()) you are shown the length of the bytes(getting out of my depth here, (??)) in the variable a.
There are only few things about python I really don't like. One of them is, that implicit behaviour is not only possible (which is acceptable), but also sometimes seems to be encouraged, although the zen of python clearly states that explicit is better than implicit.
I wouldn't see that missed comma without reading the comments, but what I would definitely do next is printing all the values of the list and only then finding this mistake.
Correct me if I am wrong, but, doesn't the indexing start from 0 instead of 1? (I'm a beginner) Edit: I understand now, the strings in line 4 and 6 have no commas, so the strings are being concatenated.
Understandable it's concatenation but bruh do all of you understand the index starts. 0. So 0 1 2 3 4 5. It looks like 5 elements but machines always count from 0 and on which is why index is still 4.
As I was trying to reproduce the error in my machine, my visual system's pattern recognition spotted a visually screaming absent comma, and so Bingo! String concatenation as other have rightly pointed out ! But was a gotcha for sure !
lol you got me, i thought there was a comma after "three". I typed it up in python 3.8 in my editor and it was working, i put the comma after "three". i was like what the heck?
the author of the channel just bait people. Length 4 because the author deliberately did not put a comma and the strings were concatenated: ['one', 'two', 'threefour', 'five'],
explanation:
adjacent string literals are implicitly concatenated.
on lines 4 and 5, the two strings "three" and "four" are concatenated into "threefour"
exactly :)
yeah... this is not a bug... it is a string concatenation.
@ In other word, it is a *feature*
@@infienite9215 U seem to be a minecrafter
@@patloeber
s="foo"
id(s)=140542718184424
id(s[0])= 140542719027040
id(s[1])= 140542718832152
id(s[2])= 140542718832152
I did not understand how each character is getting stored in memory and and why id of ' s ' is not equal to id of s[0] (like it use to be in c) and why id of s1 and s2 are same? can do a video in this topic
This guy is honestly just training us to spot errors when we have to fix our own code
where's a ","?
hes just trying to make you reproduce his video for more time possible in order to go into reccomendations
Missing coma
@@simone1377 You don’t need to run this to see the problem.
🤣🤣🤣🤣
Lines 3 and 4 are not separated.
yeah you forgot the comma after "three", so Python think that "three" and "four" is one element (and they both are concatenate)
important to note it only works for strings
But counting actually starts by 0
So shouldn't it be 3
@@technicalmaster-mind It would be 0, 1, 2, 3 indexes but the total length would be 4
А теперь объясни, пожалуйста, на кириллице ))))
@@prokopiidestroypizza2691 он не поставил запятую после three, и компилятор объеденил 3 и 4.
line 3 and 4 are not separated they are one line therefore the answer is 4 if you put a comma after string "three" then the answer will be 5
Missed a "," so three and four concat. Lmao. I've done this so many times.
there is no comma between "three" and "four" so it is considered as a single string "threefour"
In between 3 and 4 you don't separate it with comma (,) that's why it's considered as a one combined string ( "threefour")
I don't see an issue here. Between "three" and "four" there is no comma, thus concatenating them into one string. This will result in having four strings in the array.
This is intended behaviour for very large strings, so that one can break them into multiple lines.
Edit: I guess one could say: "It's not a bug. It's a feature. :)"
I don’t really like this implicit behavior though. I think that there should at least be a plus between the strings so they concat.
This implicit behaviour is the reason python is known for being error prone (especially the fact that it has no types). This is a serious issue
@@pawelpow type hinted by is a thing since 3.5
It’s not the language is the dev
@@pawelpow string concatenation like this is in many languages. Including c and c++. So its not a python script
@@pawelpow I've been employed at a company developing a Python backend for 2 years now and this has never happened to me accidentally. So I think calling it a "serious" issue is a bit too dramatic. I'm not a Python fan though, but for other reasons
Explanation: “three” and “four” are treated as “three”+”four”
Therefore there really is 4 items
Otherwise known as bad code. This video is clearly a bait to get attention
Wait, i was thinking because count : 0, 1, 2, 3, 4
Edit: i just see that miss a comma
IF a Junior run that code:
Python: "error at your brain"
Sênior:
Python: "Nothing wrong here"
Sorry, that is an example of Python being a bad language.
@@richardpaulhall no it's not, he didn't put a comma after 3 which concentrated the value to be one as it was never differentiated. Nothing shows it as a bad language here
@@yairkaz However, this python feature may cause some unexpected results when coding a big proyect. Imagine having this problem in thousands lines of code 😖
@@alexandropalacios7782 it may be annoying but I feel like in a huge project there would not be much lists like this
@@richardpaulhall It's arguable, by the same standard I could point to a hammer a person just used to bang his own finger, and say, "Sorry but that's an example of a bad tool"
Three n Four are concatenated into ThreeFour it’s counted as one string. Add a comma between then and it should print 5
He didn't put a comma to separate "three" and "four", thus they catenated to one and reported a list of 4 items 🚶♂️
And this is an example of why Python is a crappy language.
@@richardpaulhall thats why i love C. Python is confusing
@@ayushyadav5164 This is actually a feature copied directly from C.
It's often used to concatenate string literals inside macros.
If you want to see length of list equal to 5 you need to add a comma after the string « three »
Without a final comma, the string « Three » will be a literal that will be concatenated to the string « Four ».
Haha you got me there by missing that comma 🤣
No u just got it wrong ... a comma is missing
Comma after "three" and "four" be like "Mujhe andar to lo"😂.
What language is that?
@@__lasevix_Portugese
there is also supposed to be a comma after three
", " missing after "three"
Logical error detected
Yea, but why can’t python just throw an error. If u wanna concat strings it should require an plus or a function
@@derfrederikhd1931 yeah u are having good point.
Look at the pinned comment, or we should try doing practical.
It may help
@@taranveersingh05 I don’t use python. I prefer when u can set the type of a variable.
I am not a programmer but what I can see is that you missed a comma after "three" I think that's why it is showing 4 . Please correct me if I am wrong
Spot on!
I definitely think this should throw a compile time error. Its strange and unexpected behavior for most devs, even as someone who has been using python exclusively for the last two years, I spotted the missing comma but though its going to throw a syntax error, not implicitly concat them.
On the same note, people should watch our for additional commas (not only missing commas) as well as commas are what syntactically create tuples not round brackets. You might mistakenly create tuples if you place a comma by mistake somewhere.
But python isn't a compiled language
@@zakinadhif syntax error
@@fardinahsan2069 ahh, imo syntax warning would suit better.
@@zakinadhif No, a syntax error.
Its counting from 0
The "three" and "four" concatenated in 1 line (miss the , in the end) so is correct.
',' is Missing after "three"
Which means "three"&"four" is a single element
Thats why len(a) = 4
✌️
That is because of "string literal concatenation" in python; if you try to write codes in iterables like lists and tuples (or just regular parentheses) with the block structure like in the video and your data type is just string, if you miss comma, SLC whould happen.
in the first look SLC maybe seem undesired but it could be usefull sometimes. for example you can split up long lines in two or more between parentheses:
print("long line")
print("long"
"line" )
the output whould be the same but it makes your code cleaner.
You didnt put a , before the four so it counts as 4 instead of 5
Whats the name of the color theme on vs code?
I'm laughing so hard, out of all the python jokes I've seen this was the funniest one I dont know why
One comma ruins everything
Haha?
check the pinned comment
@smhsmh his profile pic
God damn it. This is triggering PTSD flashbacks. When missing commas, fullstops, semicolons and typos escape the compiler without errors but breaks days of work...
In simple words index starts from 0
No comma seperation between 3 & 4, which results in concatenation. No sorcery here, just print the iterable and you'll figure out.
Missing coma in after "three"
You forgot a ,
No es un bug para contar toma como el primer objeto como 0 y ahí va sumando así es que 1 = 0 2= 1
Hey, can you tell me: which text editor is best for python
It's because you forgot the comma after the string three so it treats it and the four string as one and not strings
it is a feature because every start of a list will be 0, for example: var list = ["a", "b", "c"] print(list[0])
>>> a = [
... "one",
... "two",
... "three",
... "four",
... "five"
... ]
>>> print(a)
['one', 'two', 'three', 'four', 'five']
>>> len(a)
5
python3 --version
Python 3.8.10
mmmh
oh, nvm i'm blind. Also gotta agree. The most annoying part of learning any programming language is my brain filtering out vital stuff or doing the good ol' "aww, come on. it's cool. what could go wrong?"
.
This is because the length or the index starts from 0 so that is why it printed 4 instead of 5
No it's not a bug it is because the first list item is said to be in index 0, and the second item is said to be in index 1, and third item is index 2. The fourth is 3rd index. The fifth is index 4th
Python is c-like in that it is 0-based indexed. So “one” is 0 and “five” is 4 in memory. So when u print the length (len()) you are shown the length of the bytes(getting out of my depth here, (??)) in the variable a.
There are literally 4 objects in the list.
.length doesn't start with 0.
Can somebody tell me what shortcuts did he use to write this code. I'm at the very beginning, and I wanna pick up on how to do things efficiently
Creo que es porque len considera la lista desde posición 0 entocnes hay 5 elementos. Por eso se le resta uno y sale 4
Where is comma after string three?
There are only few things about python I really don't like. One of them is, that implicit behaviour is not only possible (which is acceptable), but also sometimes seems to be encouraged, although the zen of python clearly states that explicit is better than implicit.
Each time in list is separated by commas, a comma is logging and stings between comma are concatenated as one string.
Didn't give comma after 3
I wouldn't see that missed comma without reading the comments, but what I would definitely do next is printing all the values of the list and only then finding this mistake.
THE COMMAAAAAAAAA
It’s because the first word is 0 and second in 1 instead 1 it starts with 0
Yeah length doesn't work that way. Length says there are 4 objects, and there are indeed 4 objects.
It’s because there’s a missing comma after three, leading to implicit concatenation of “three” and “four” into “threefour”
Is it because when iterating the program starts at 0 and goes 0, 1, 2, 3, 4. Therefore its still counting 5 strings.
it's true because of in index 2 or three and four can count together
He also gave an explanation in the description.
Really a Good and helpful short video in my opinion.thnak you
Since when the list index starts from 1
Did you spot the bug? And do you also know what's happening with the strings? I will pin a good explanation :)
Manipulation ,not a bug:)
use a come (,) after three
This is like the university researchers purposely inserting a bug into the Linux kernal.
I considered adding this feature to my parser and promptly decided not to for this exact reason
Yup, same.
How did you create a list that fast?
I thought index value starters from 0
Index - yes, but no language will count starting from 0. The list is just 4 elements (almost every other comment explains why) long.
len doesn’t tell you the “ last index “ but total quantity of the items in a list (array)
You didn't add the comma after " three"
Please put a comma after a string three, your array is concatenation those two strings
I didn't get it at first - but after rewatching I immediately spotted the missing "," at the end of line #4
But index start with 0 right
Whats your vscode theme?
You could type print(2+2) and even if it prints 5 your issue will still be closed as a wontfix
Is implicit string concatenation a good idea? It’s in C, C++ and Python, but not in Java or PHP, or in C♯ that I can tell.
I personally like it.
It's an intended feature in every language unlike some weirdos ( *cough cough, LUA* ), list/array objects' index ALWAYS starts at 0.
color scheme?
*Le me realising the comma he forgot after three and four after trying this in my computer 🤣😂
because three and four are not seperated by comma, so that are treated as single concatenated string. HappY coding! :)
"why do you like strict typing? Dynamic typing is so much easier"
Least my code tells me when I made a super simple error like this
C and C++ have the same feature though. This has nothing to do with typing
@@stewartzayat7526 it would throw an error though. This some how turned "three" "four" into one object, not sure how, I don't use this language
@@Kate-m5v1e no, it wouldn't throw an error, it would run just fine. As I said, C and C++ have this feature too.
@@stewartzayat7526 just tried in it c++ "expected a ","" what compiler do you use that allows for this
@@Kate-m5v1e my cpp file looks as:
#include
int main(int argc, char **argv) {
const char *arr[] = {
"one", "two", "three" "four", "five"
};
printf("Size is: %zu
", sizeof(arr) / sizeof(arr[0]));
return 0;
}
I compile just fine with
g++ main.cpp -o main
I don't understand what's the problem. What else it should return for list of 4 elements? Someone please explain
In python the index starts with zero thats why you are getting the output as '4'
What theme is it
Is it length or index of last item.
List index starts from 0 so 0,1,2,3,4
between "three" and "four" dont have a separator (in this case ",") becouse this, "three" and "four" are considered one value
Wow python such mature language
the string are concatenated b/c of you forget to add comma btwn line 3,4 so py reads 34
Correct me if I am wrong, but, doesn't the indexing start from 0 instead of 1?
(I'm a beginner)
Edit: I understand now, the strings in line 4 and 6 have no commas, so the strings are being concatenated.
nope, if you have 3 strings you will get the result 3.
@@r0lfu_ oh, okay
"Finally, zero-indexed length operations...! Oh, nope, just a missing comma. Damn."
Please sir tell me which theme are you using
forgot to put a comma after three
Understandable it's concatenation but bruh do all of you understand the index starts. 0. So 0 1 2 3 4 5. It looks like 5 elements but machines always count from 0 and on which is why index is still 4.
Is is because there's no comma after three?
What ide do you use for Python,
For me pycharm as problems
As I was trying to reproduce the error in my machine, my visual system's pattern recognition spotted a visually screaming absent comma, and so Bingo! String concatenation as other have rightly pointed out ! But was a gotcha for sure !
What IDE do you use?
Hehe.. you missed the comma there.. purposely. I am learning python from you bro. Happy to see you.
Do you know python array starts at 0,1,2,3,4
There is no coma after three so thats why it is showing like that
Where is comma after "three"?
You didn't give a comma after 'three'
Not sure if the missing comma after the three is the problem... But most languages start to count at 0 so you have to add 1 to the result ^^
this is a bug depending on how you implement it, in this case it is the developers fault for concatenating the strings "three" and "four".
lol you got me, i thought there was a comma after "three". I typed it up in python 3.8 in my editor and it was working, i put the comma after "three". i was like what the heck?
You have to put comma betn three and four
List length is starting from 0 th index 0,1,2,3,4 ..
I think its because the 1st item is index 0 and item 2 is index 1 and so on
comma separated is missing thats why it shows 4 not 5
the author of the channel just bait people.
Length 4 because the author deliberately did not put a comma and the strings were concatenated:
['one', 'two', 'threefour', 'five'],
You purposefully missed a comma, it’s a clickbait, not a but or a feature, it just works as it is written