r/pythontips • • Jul 13 '20

Python3_Specific “Understand python DONT just remember it”

I don’t understand this why people always say “Know why youre typing the code, dont just remember the code” but how do i know what to type if i dont remember the code? o.O

38 Upvotes

16 comments sorted by

2

u/benzoboy604 Jul 13 '20

nicely worded, thanks

28

u/TheSlenderman871 Jul 13 '20

Because it's figurative. You know what the end goal is, but how is up to memory.

If I said "build a house", you'd remember some of the hard parts but you sure as hell wouldn't remember every nail you put in the walls.

1

u/[deleted] Jul 13 '20

As time moves on you wouldn't want to keep building the same house anyways. You would learn new tricks from looking at other peoples work and you would incorporate it as you go. Soon, you become a master house builder.

8

u/[deleted] Jul 13 '20 edited Jul 13 '20

It means don't treat blocks of code as "black boxes" that you copy and paste as you need them. You shouldn't need to remember exactly how you did some task if you understand it.

If you're only memorising code (or just copying blocks off the internet) and not understanding it you won't know how to modify it to do something slightly different, fix it if it breaks, or even check it is safe code to run.

Obviously you need to remember how to write python, but just memorising isn't learning.

4

u/j19sch Jul 13 '20

This.

Copy-pasting, pattern matching and trying almost random stuff until the code does what you want it to, is a normal first phase of learning to program. However, I've seen people get stuck in that phase and as a result never learn Python. The understanding is not there, it's all manipulation of black boxes.

1

u/Pavulon18 Jul 13 '20

This is the phase I'm in right now. Fortunately for me, programming isn't my job. I am trying to learn so that I may one day transfer out of my current career, but it's been an arduous but fun task.

1

u/benzoboy604 Jul 13 '20

i feel like i know where all the “nails go”, i just dont remember what to type.. for example.. this is a calculator im stuck on. i used comments to decribe the code that should be there.

numberone = int(input('number 1: '))

numbertwo = int(input('number 2: '))

‘math type’

def add(x, y): return x + y

def sub(x, y): return x - y

def mult(x, y): return x * y

def dev(x, y): return x / y

''' select math type (1add, 2sub, 3mult, 4dev)

if 1 selected then add

elif 2 selected then sub

elif 3 selected then mult

else 4 selected the dev '''

''' print (numberone/two > selected math type > math type equation > print back answer) '''

4

u/Peanutbutter_Warrior Jul 13 '20

So you know you need an if statement, so just Google 'python if', and the correct syntax will be there. If you just can't remember syntax just Google it

9

u/Peanutbutter_Warrior Jul 13 '20

The advice isn't too forget the code, it's to not remember the grammer. You should remember what an if statement is and what it does, but not worry about remembering the colon. That's easily searchable. If you find some code on stackoverflow that does a job, rather than remember the code as a whole remember what it does so you can come back for it when you need it

3

u/b10011 Jul 13 '20

And if you understand the code, next time you might be able to code it without copy-pasting. Always copy-type to understand, never copy-paste.

2

u/JeamBim Jul 13 '20

It is better to know what a programming language can do than to remember how to do it. You can always look things up, but if you just remember code without knowing why, you will use the wrong solutions a lot.

2

u/tomkatt Jul 13 '20

but how do i know what to type if i dont remember the code?

IMO that's what Google is for. I can't remember all the syntax for most of the languages I've written code for, but the logic underlying the syntax is universal.

1

u/dxspicyMango Jul 13 '20

When I had my Introduction to Python class in my first year in college, I had friends who literally copied the code the teacher had put on the board. They didn't know how basic functions like while, for, or ifs worked. Even if you're going to copy code from Stack Overflow most of the time you need to understand its functionality. so you can adapt it to your needs.

1

u/Ifhes Jul 13 '20

You will need memory, for sure. It's like learning multiplication or learning a new language. You can memorize a bunch of stuff and it might help you pass an exam, but you will not have the skill. Understand multiplication, understand the language grammar structure. That will allow you to do any multiplication or phrase respectively but at the end you will need to memorize stuff.

1

u/LirianSh Jul 16 '20

If you do the same thing 10-15 time you will probably start memorizing but you will still have to go use google. Programming is more about finding out how to do it than doing it

1

u/SloppyPuppy Jul 13 '20 edited Jul 13 '20

if I tell you to write a bubble sort algorithm (simple example). dont remember it row by row. understand the concept and write your own bubble sort.

I interview a lot for python development. there are some people that when presented a new problem will just say "I never did it so I dont know" or "ill find a solution in google." so, understand the code or the concept, dont program by memory.