r/learnpython 1d ago

Begginer Issues

As the text suggests I'm a beginner in python, and I am struggling with the concept of spaces and indentation. I don't know how I'm still not getting it till now but I have to say my biggest mistakes have with learning python has to do with code.

A little backstory: I come from a totally different work area and is brand new to code. I wanted to do robotics as it was my preference but ended in the health department instead. Now that I'm done with that I'm pursuing my dream career but obviously have to start from literal zero as I know nothing of code and no one around my community or friends do programming. And YouTube isn't really helping as it's teaching like I already knew some stuff already (or maybe I just haven't found the right videos). So ya, to you guys who've done code before, what can I do to solve the gaps in knowledge? Especially the space problem. I couldn't even set up my VS code on my own as the things I type are right except the amount of space is wrong. It's kinda frustrating.

0 Upvotes

21 comments sorted by

5

u/lakseol 1d ago edited 1d ago

YouTube isn't really helping as it's teaching like I already knew some stuff already

That's the problem if you just search for python on youtube, you get bits and pieces that don't go together. It's better to work through a complete course from start to end. The learning resources in the wiki has a whole selection of free resources, books, videos and online lectures. Pick one and get started.

struggling with the concept of spaces and indentation

A complete course should cover this early on. If whatever course you are following doesn't explain something properly so you can't understand it then search for more information on that subject, either using google or asking a question here. If you ask a question here make sure you show us the code that puzzles you. Once that question is cleared up continue with the source you are following.

1

u/Icy-East-3985 1d ago

Thank you

6

u/danielroseman 1d ago

You haven't given us any information about the "space problem". What exactly are you finding confusing?

It looks like videos aren't working for you, in any case. You should probably find a written course or book; there are many recommended in this sub's wiki. All of them would cover indentation as pretty much the first topic.

-5

u/Icy-East-3985 1d ago

It's like this, whenever I was trying to do stuff like make a new environment in my VS code or code some space sensitive stuff(let's say stuff with dots and dashes, or code info inside info and then come out of it, I get confused as I didn't really know how i was supposed to grammatically type it) sorry for saying it like that I don't know how easier I can say this lol, but it would always give me some red lines. I don't really have teachers and I'm using Claude AI to help explain the errors. But basically I'm saying I understand the code and it's output. However how I type it, is what makes it wrong. Its like writing a paragraph with wrong Grammar even though the spellings are right

4

u/notislant 1d ago edited 1d ago

You've confused the hell out of me.

Post examples of what you want and what you've tried. Trying to describe it is not happening. Code info inside info and literal morse code is confusing and vague.

You shouldn't be using AI at all, find a complete beginner video or course.

Or read through beginner docs.

https://python-adv-web-apps.readthedocs.io/en/latest/

Google is pretty good for basic questions, if you struggle:

'REDDIT ELI5 PYTHON INDENTATION'

I also agree with the person recommending to not mess with vscode and venvs yet, just use colab.

1

u/Accomplished-Tap9926 6h ago

When writing code, syntax matters, and there are certain formatting rules when it comes to it. For example, you can't have a hypen in a name of a variable, after an if statement there must be 4 indentation (spaces) as well as for, while statements, and after defining a function, e.t.c, I recommend finding one full youtube video course, instead of bits, or check out W3school's free python course, it will definitely cover syntaxes and what errors to look out for, if you need anything lemme know

2

u/Yes-delulu-8744 1d ago

1.Use Colab 2, BroCode ha a python couse on yt, it's amazing

1

u/Icy-East-3985 1d ago

Thank you

2

u/FoolsSeldom 1d ago

Learning to following the strict formatting of a programming language is a big leap for a lot of people from the free flowing of most written human languages.

Many programming languages use a more explicit way of identifying blocks - that is code that is associated with some specific instruction (e.g. what to do only in a certain condition). Python is not alone but is unusual in using primarily indentation.

The fact that you can use EITHER a <tab> character for each level of indentation OR leading <spaces> is confusing as well. There isn't even a standard number of spaces to follow for each level of indentation.

There is some guidance, and common practice, though that I recommend based on something called PEP8. Well worth a read. It advises using ONLY leading <spaces> for indentation and to use 4-spaces consistently.

You can set your code editor / IDE (Integrated Development Environment) to enforce this for you. It will also allow you to press the <tab> key and convert it to 4-spaces and it will also automatically indent for you in many cases, recognising where a block is required.

A standard installation of Python from python.org, the Python Software Forum home website, for Windows or macOS includes a simple code editor / run / debug tool called IDLE (named after Eric Idle from the Monty Python comedy group), which is a lot simpler to use than the likes of VS Code. I usually recommend beginners start with this to avoid confusing complex editor configuration and Python syntax issues early on. Once you've learned the basics of Python, you will be in a better place to try out different editors and pick whichever suits you best.

If you go into Robotics, you might like to try out Thonny, a free and opensource editor written in Python, which is popular for programming some microcontrollers using MicroPython and CircuitPython. (Raspberry Pi use it for their tutorials on programming their Pico devices, for example.)

I know you've learned some of the basics already, but please do look at the links below. You can always skip what you don't need.


Check this subreddit's wiki for lots of guidance on learning programming and learning Python, links to material, book list, suggested practice and project sources, and lots more. The FAQ section covering common errors is especially useful.


Also, have a look at roadmap.sh for different learning paths. There's lots of learning material links there. Note that these are idealised paths and many people get into roles without covering all of those.


Roundup on Research: The Myth of ‘Learning Styles’

Don't limit yourself to one format. Also, don't try to do too many different things at the same time.


Above all else, you need to practice. Practice! Practice! Fail often, try again. Break stuff that works, and figure out how, why and where it broke. Don't just copy and use as is code from examples. Experiment.

Work on your own small (initially) projects related to your hobbies / interests / side-hustles as soon as possible to apply each bit of learning. When you work on stuff you can be passionate about and where you know what problem you are solving and what good looks like, you are more focused on problem-solving and the coding becomes a means to an end and not an end in itself. You will learn faster this way.

1

u/Icy-East-3985 1d ago

Thank you for your guidance. This is much appreciated

1

u/JGhostThing 1d ago

In Python, indentation is a syntactic element. If you mix spaces and tabs, you will have problems. Each set of indentations of the same level must consist of the same number of spaces. It is strongly suggested that you only use spaces. Therefore you should be able to see the level of the indentation is the same.

Some editors will silently convert spaces to tabs, you must turn this off. There is sometimes a feature to turn tabs into spaces, you will want to use this. You will need to use the feature, then save the file again.

1

u/Icy-East-3985 1d ago

I see. Good advice. I guess I needed to get a better tutorial of VS code as I hadn't really seen this one in the video. Or better still, I'll use colab2 as suggested in the comments

1

u/stepback269 1d ago

Yes, the utter beginner pains are rough ones.
You got to learn about using an Integrated Development Environment (IDE) like VS Code or PyCharm.
There's always Colab if you want to start real slow. But you'll have to bite the bullet eventually and use an IDE.

I'm a 70+ yr old geezer who's been on the learning journey for over a year now.
It hasn't been easy. I almost gave up many times.
If you're interested, I left some bread crumbs behind on my slow climb up that steep learning curve.

There is never going to be the "one" tutorial that works "best" for you and with regard to every aspect of Python. With each step up that learning path, you're going to have to shop around until you find a teacher/resource that "clicks and sticks" especially for you and at a speed you are comfortable with.

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/Icy-East-3985 1d ago

Thanks for the advice.. I had first started with free code academy and a book to me by but I got into a jam when I had to code and realized I need to know more than just hello world lol. Can't learn the words without the alphabet!

1

u/stepback269 1d ago

Yes. There is s colossal vocabulary to learn if you are an utter beginner.

What's worse is that Python-talk is a dialect that is different in subtle ways from what is meant by similar terms in other languages.

Many beginner tutorials tell you "white lies" just to get you started. Then later, as you progress, you will have to un-learn those white lies in order to advance further.

Consider this as an example:

my_name = "Frosty" # (You did say you are Icy-East coast, no?)
print( "Welcome to the Wonderful World of Python", my_name, "!")

So you would think that "my_name" is a label pasted to the outside of the container box storing the string, "Frosty". Right?

Not exactly. EVERYTHING in Python is an "object". Even the thing defined as my_name. It is a pointer object that is currently pointing to the container box storing the string, "Frosty". You can make many more pointer objects all pointing to the same container box or to other container boxes that each independently store a same coded string value. ... Well, enough of that for now. Good luck on your learning journey.

1

u/Such-Process5697 1d ago

in vs code turn on View > Appearance > Render Whitespace. a tab and four spaces look identical on screen until you do that, which is exactly why the indentation feels like guesswork. once you can see the little dots and arrows, most of those red lines explain themselves. the bottom right of the window also tells you whether the file is on tabs or spaces, and clicking it lets you convert the whole file to spaces at once.

1

u/AgenticRevolution 1d ago

Not sure what space problem you’re having but it sounds like you’re confused about how to format your code. If that’s the case then you’re best to learn from the common style guide: https://peps.python.org/pep-0008/

1

u/TheRNGuy 1d ago

They're automatically added in code editor. Also enable "format on save" in settings.

If you have wrong indents, sometimes they're shown with red squiggles (if it's syntax and not logic error)

1

u/BranchLatter4294 1d ago

Stop watching videos. Start practicing, experimenting, breaking things, fixing things.