rootblysub
All videosYouTube Subtitle Translation한국어

Python Comments: Visually Explained | #Python Course 3

0:00
Sziasztok! Most az első dolog, amit általában megtanulunk egy programozási nyelvben, az az, hogyan írjunk megjegyzéseket a kódunkba.
Hey friends, so now the first thing that we usually learn about any programming language is how to add comments to our code.
0:07
Mik azok a megjegyzések? A megjegyzés egy szövegsor a kódodban, amelyet a Python teljesen figyelmen kívül hagy.
So what are comments? A comment is a line of text in your code that Python totally ignores.
0:13
Csak azért van ott, hogy segítsen megérteni, mit csinál a kód. Rendben, nézzük meg, pontosan hogyan működik ez.
It is there only to help us in order to understand what the code is doing. Okay, so now let's understand how this exactly works.
0:21
Tegyük fel, hogy egy Python-szkripten dolgozol, és szeretnél hozzáadni egy megjegyzést.
So now let's say that you are coding a script in Python and now you would like to add a comment.
0:25
Ehhez a speciális kettőskereszt karaktert használjuk
So now in order to do that we use the special character hash
0:28
utána pedig bármit írhatsz, például azt, hogy „kezdés”
and after that whatever you want like for example start
0:31
majd azt, hogy „ez a kódom”, aztán egy
and then you say this is my code and then an
0:34
„vége” szót. Ha most lefuttatod, a Python azt mondhatja:
end so now once you execute this what can happen python can say
0:38
„Rendben, ez nem kód, csak embereknek szól.”
okay this is not a code this is just for the humans
0:41
Aztán teljesen figyelmen kívül hagyja. Ez azt jelenti, hogy
and i'm gonna go and totally ignore it so that means
0:44
valójában semmi sem történik: nem befolyásolja a kódod logikáját vagy a kimenetet, csak neked szóló megjegyzés. De akkor miért van szükség megjegyzésekre?
actually nothing happens it will not affect the logic inside your code or anything in the output it is just a comment for you so now if you say you know what why do we need comments
0:55
Nézzük meg! Bal oldalon egy működő kódot látunk. De elég rejtélyes, igaz?
Now let's check this. On the left side we have a code that is actually working. But it is kind of mystery right?
1:00
Van benne valamilyen szűrés, és dolgokat szorzunk össze. De nagyon nehéz megérteni és elolvasni.
There is like some kind of filtering. And we are multiplying stuff together. But it's really hard to understand and to read.
1:07
Most nézd meg a jobb oldalt! Ugyanaz a kód, de ezúttal megjegyzésekkel magyarázzuk el a lépéseket.
Now if you look to the right side. We have the same code. But this time we are adding comments. In order to explain the steps.
1:14
Először azt írjuk, hogy betöltjük az adatokat. Aztán
So first we are saying okay we are loading the data. Then we
1:17
hónap és régió szerint szűrjük az adatokat,
are filtering the data based on the month and the region
1:20
majd kiszámítjuk a bevételt, és a
and then we are computing the revenue and at
1:23
végén megkeressük a teljes bevételt, majd megjelenítjük.
the end we are finding the total revenue and we are displaying it
1:26
Szóval pontosan ez a kommentek ereje, amiket írni fognak.
so this is exactly the power of the comments they're gonna make
1:29
a kódodat, olvashatóbbá és professzionálisabbá. Hidd el, később hálás leszel magadnak, amikor egy hét vagy akár egy év múlva visszatérsz a kódodhoz, vagy amikor valaki a csapatodból
your code understandable readable and professional and believe me you're gonna thank yourself later once you come back to your code after a week or even a year or someone even from your team
1:41
megnyitja a kódodat, és meglátja ezeket a nagyszerű
once they open your code they will see these amazing
1:44
megjegyzések, hogy megértsük, mi a logika
comments in order to understand what is the logic
1:47
logikáját. Pontosan ezért írunk megjegyzéseket a
of your code so this is exactly why we add comments to our
1:50
kódunkba. Rendben, térjünk vissza a Visual Studio Code-hoz, és
code okay so now back to visual studio code and let's go and
1:53
írjunk egy megjegyzést. Kezdjük egy egyszerű kettőskereszttel, és
add a comment so we're gonna start with a simple hash and
1:56
azután azt írhatunk, amit akarunk, tehát ez
then after that we can write whatever we want so this is
1:59
egy megjegyzés. Ha most lefuttatod, láthatod, hogy a kimenetben nem kapunk semmit, mert a Python először azt látja, hogy van
a comment and now if you go and execute it you can see in the output we are not getting anything because python at the start sees okay we have
2:07
ez az egyszerű kettőskereszt, tehát ami utána jön
this hash simple so that means whatever comes after it
2:10
az embereknek szól, nincs mit végrehajtani, a Python pedig
it's for human so nothing to execute and python can
2:13
menj, és hagyd figyelmen kívül, és most persze ez a megjegyzés, amit épp létrehoztunk,
go and ignore it and now of course this comment that we just created is
2:16
egysoros megjegyzés, tehát ez egyetlen sor
a single line comment so this is a single line
2:20
de néha szeretnénk több leírást hozzáadni a kódunkhoz, és
but sometimes in our code we would like to add more description and
2:24
több sort szeretnénk használni. Ezt persze megtehetjük, ha minden sor elejére kettőskeresztet írunk. Ez a többsoros megjegyzés. Most további sorokat is hozzáadhatunk.
we would like to have like multiple lines and of course we can go and do that if you start always with the hash so this is multi line comments and now we can go and add more lines of comments
2:36
Például először létrehozzuk a felhasználónevet, aztán talán
Like we say first create user name, then maybe
2:39
második lépésként üzenetet írunk ki a
a second step we print message to
2:43
felhasználónak, harmadik lépésként pedig adatokat tárolunk
user and a third step store data
2:46
amint látod, most többsoros megjegyzéseink vannak. Ez
so as you can see we have now multi-line comments this is
2:49
nagyon hasznos, ha összetett logikád van, és lépésről lépésre szeretnéd elmagyarázni
really nice if you have like complex logic and you want to explain it
2:52
Rendben, barátom, többféleképpen helyezhetjük el a megjegyzéseket a kódban. Nézzük meg: a kódunkban például ez áll: x egyenlő 10.
like step by step okay so now my friend there are like different styles on how to place the comments inside your code so now let's that in our code we have something like this x is equal to 10.
3:03
Ha most megjegyzést szeretnék hozzáadni, hogy elmagyarázzam
now if i would like to add a comment for this in order to explain
3:06
ezt, általában a megjegyzést ide írjuk,
it what we usually do is we go and place the comment on
3:09
a tetején, tehát például azt mondjuk, hogy tároljuk a végső
the top so for example we say store the final
3:13
vizsgaeredmény, hogy megértsem
exam score so that i understand
3:16
rendben, most a 10-es pontszámot tárolom a
okay i'm storing now the score 10 to the variable
3:19
x változóban. A szintaxis miatt ne aggódj, a következő videókban megtanuljuk.
x don't worry about the syntax here we're gonna learn it in the next videos
3:22
Tehát a kódunk fölé írtunk egy megjegyzést, amely elmagyarázza a következő kódsort.
so what we have done we have placed a comment on top of our code that explains the next line of code
3:29
Van egy másik módszer is: a megjegyzést a sor végére írjuk. Hadd menjek
and now there is like another style where we add comments let me go
3:32
ide, és írjam azt, hogy x egyenlő 9-cel.
over here and say x is equal to 9
3:35
Most ahelyett, hogy a kód fölé írnánk a megjegyzést,
now instead of putting the comment on top of the codes
3:38
a kódsor végére tesszük a megjegyzést, tehát
we will place the comment at the end of the code so we're
3:41
azt mondjuk, hash végső vizsgaeredmény
gonna say hash final exam score
3:44
ahogy látjátok, minden egy sorban van, és ezt
so as you can see everything is in one line and we call
3:48
ezt a megjegyzést beágyazott megjegyzésként, ilyen típusban
this comment as inline comments this type
3:51
megjegyzés nagyon hasznos gyors magyarázatokhoz, és általában röviden tartjuk. Ahogy látjátok, nem azt írtam, hogy tárold a végső vizsgaeredményt, csak
of comments it is really amazing in order to give a quick explanation and we usually keep it short as you can see i didn't say store the final exam score, I just
3:59
röviden és tömören akartam fogalmazni: végső vizsgaeredmény.
want to make it quick and short and say it here, final exam score.
4:03
Ha most lefuttatod, a Python nem hagyja figyelmen kívül az egész sort, mert két dolog van benne. Először is van egy kódunk.
So now if you go and execute this, Python will not go and ignore the whole line because the line has two things. First, we have a code.
4:11
A Python tehát végrehajtja ezt: x egyenlő kilenccel. A következő résznél viszont azt mondja: rendben, itt egy egyszerű megjegyzés.
So Python going to go and execute this. X is equal to nine. But the next part, Python going to say, okay, we have here hash simple.
4:17
Ez azt jelenti, hogy a Python csak az utána következő részt hagyja figyelmen kívül, nem az egész sort.
So that means Python going to go and ignore everything after it, not the whole line.
4:22
Ha hosszú és részletes magyarázatot szeretnél írni, tedd a megjegyzést a kód fölé, és akár több sort is hozzáadhatsz.
So again, if you want to make a long and detailed explanations, place your comment above your code and you can go and add multiple lines and so on.
4:31
Ha viszont rövid, gyors magyarázatot vagy címkét szeretnél adni, a megjegyzést a kóddal egy sorba, közvetlenül a kód végére írhatod.
But if you'd like to give short and quick explanation or a label, you can go and place your comment in the same line exactly at the end of your code.
4:40
Rendben, akkor röviden foglaljuk össze. A megjegyzések olyan szövegsorok, amelyeket a Python teljesen figyelmen kívül hagy. Csak nekünk, embereknek szólnak.
OK, so now a quick recap. Comments are line of text that Python totally ignores. It is written only for us, for humans.
4:47
Megjegyzéseket azért írunk a kódunkba, hogy érthetőbb, olvashatóbb, professzionálisabb és könnyebben karbantartható legyen.
And we add comments to our code in order to make it understandable, readable, professional, and easy to maintain.
4:52
A jövőben neked és a csapatodnak is segít megérteni a kód mögötti gondolatmenetet. Ennyit a megjegyzésekről.
It's going to help you and your team in the future to understand the thought process inside your code. So that's all about the comments.

Only the first 5 minutes are free. Install the app or extension to keep watching.

Download
Request another language
Also available as a Chrome extension and mobile appDownload
Translating0%