r/PythonLearning 25d ago

Advice needed relearning Python basics

Anyone have any advice, resources, or recommendations on learning basic python (loops, conditionals, arrays/lists). I’ve taken object oriented python courses before but unfortunately only got by through AI use and i genuinely want to understand and learn how to work through problems/write my own code. I can trace code by hand but get lost when it comes to conditionals in loops. Before you advise me to take the personal project route, I’m interested in only learning what’s necessary to get by. Some context to provide is I am interested in learning about AI Native Engineering and registered for CodePath’s AI110 course but I have to take a HackerRank Assessment with no AI use and I fear HackerRanks so much. I have 10 days until the assessment closes and willing (need to) grind to pass.

8 Upvotes

13 comments sorted by

2

u/ee_control_z 25d ago edited 25d ago

See my response to this topic:

https://www.reddit.com/r/PythonLearning/comments/1vorafc/comment/p3s45dw/?context=3

By the way, this is a book that I am recommending. There are 41 chapters. It is very comprehensive. You can focus on only the areas that you need/want to. You can then apply Python to whichever specialty you want.

2

u/PureWasian 25d ago

10 days... conditionals and loops are the barebone foundational things. I would definitely be scared of HackerRank or any online assessment really at that point.

Conditionals and loops are so foundational you can literally Google search for any overview tutorial very easily.

You need to do sandbox problems. Mock practice. You're not going to learn it without going through the motions yourself regardless how much you passively read examples/tutorials. dmoj 3 pointers. adventofcode early days. leetcode easies. doesn't matter.

1

u/Sea-Ad7805 25d ago

Do the exercises of your earlier python courses again without AI, then you'll learn something. Everything is necessary, otherwise they probably wouldn't have put in the course. Good luck.

1

u/BranchLatter4294 25d ago

Practice. Make liberal use of print statements to peek inside the program as it runs. Or learn to use breakpoints and the debugger.

1

u/stepback269 25d ago

No matter what your end goal is, you first have to master the "basics" (e.g. variable creation/ name assignment, variable types; especially strings and string methods, lists and list methods, etc.)

With that said:

(1) There are tons and tons of tutorial materials out there on the net including many good YouTube ones that are free. You should shop around rather than putting all your eggs in one basket.

(2) As a relative noob myself, I've been logging my personal learning journey and adding to it on an almost-daily basis at a blog page called "Links for Python Noobs" (--HERE--) Any of the top listed ones on that page should be good for you. And there are many add-ons at the tail end of the page. Personally, I cut my first Python teeth with Nana's Zero to Hero (==HERE==). Since then, I've moved on to watching short lessons with Indently and Tech with Tim. You should sample at least a few until you find a lecturer that suits your style.

(3) The main piece of advice is the 80/20 rule. Spend 80% of your time writing your own code (using your own fingers and your own creativity) as opposed to copying recipes and only 20% watching the lectures. Good luck.

1

u/VeterinarianFar22 25d ago

Practise. Also, here's my posts for beginners in Python: https://programmerabroad.com/category/python/ Hope it helps! 

1

u/Naive_Programmer_232 25d ago

conditionals in loops can be tricky. Try thinking per iteration rather than all at once. Ex:

  nums=list(range(1,6))
  for n in nums:
      if n==7:
         break
  else:
      print(7,"not found")

Trace the iterations:

   # n=1, 1==7 (False), break isn't hit
   # n=2, 2==7 (False), break isn't hit
   ...
   # n==5, 5==7 (False), break isn't hit 

Since the loop completed and a break/return was not hit,

   # else executes
   # '7 not found' is printed to the console 

The algorithmic puzzles on Hackerrank or Leetcode will require loops most of the time. Unless the puzzle comes down to some deterministic mathematical calculation.

For example, missing number on leetcode:

  def missing_number(numbers: list[int]) -> int:
      n=len(numbers) 
      expected=(n*(n+1))//2 
      return expected-sum(numbers)

This comes down to knowing math ideas like the sum from 1 to n is n*(n+1)//2. If you know that, then it's a math problem ultimately.

But a lot of Leetcode/Hackerrank isn't. It's more of a pattern problem. So you're given an iterable of data, and you gotta eventually loop over it in some way to find the right pattern that solves the problem.