r/pythontips • u/Blazzer_BooM • Feb 20 '25
Syntax Is it correct
While I was learning how interpretation in python works, I cant find a good source of explanation. Then i seek help from chat GPT but i dont know how much of the information is true.
#### Interpretation
```
def add(a, b):
return a + b
result = add(5, 3)
print("Sum:", result)```
Lexical analysis - breaks the code into tokens (keywords, variables, operators)
\`def, add, (, a, ,, b, ), :, return, a, +, b, result, =, add, (, 5, ,, 3, ), print,
( , "Sum:", result, )\`Parsing - checks if the tokens follows correct syntax.
```
def add(a,b):
return a+b```
the above function will be represented as
```
Function Definition:
├── Name: add
├── Parameters: (a, b)
└── Body:
├── Return Statement:
│ ├── Expression: a + b
```
Execution - Line by line, creates a function in the memory (add). Then it calls the arguments (5,3)
\`add(5, 3) → return 5 + 3 → return 8\`
Sum: 8Can I continue to make notes form chat GPT?
12
u/Technical-Smoke5513 Feb 20 '25
Is this really how u r learning dude??
1
u/Reasonable_Bat235 Feb 20 '25
Are you an intern?
1
u/thecodedog Feb 21 '25
To be clear, you are trying to understand how the python interpreter works?
4
u/kuzmovych_y Feb 20 '25
But .... why?
2
u/Nemo_ftw Feb 20 '25
Not knowing much, but this keyword can help you look further: AST, abstract syntax trees: https://docs.python.org/3/library/ast.html
2
u/414theodore Feb 20 '25
You really shouldn’t have started taking notes from gpt in the first place. Try datacamp.com if you can afford it, or a different MOOC if you can’t if you want to actually learn python:
https://en.wikipedia.org/wiki/List_of_MOOC_providers?wprov=sfti1
2
u/SmellLikeB1tchInHere Feb 20 '25
Why are you doing this to yourself?