Starting Programming.

I just started learning Python. We haven’t started learning it in my class yet I am just trying to learn ahead since I’m completely new to it. I am about to sound like a total idiot and I’m a little nervous to ask this. But Programming is confusing me a little bit. I’m starting to understand the very basics of python, but how does code work? why can we just type like normal? I can see how the Syntaxes are working but it doesn’t explain the “Why this is how programming language works”

Try cs10.org for a gentle introduction and overview of CS.

You aren’t an idiot - the questions are actually pretty good ones to ask.

A car is a machine for going places quickly. Maybe you already know how to walk to go places. Why can’t you get into your car and just walk like normal, just faster? But that isn’t how it works, is it?
So … Your computer is a machine. You already know how to write …

In both cases, you have to interact with an inflexible machine, and since the machine is mind-blowingly stupid, guess who has to be the flexible one (hint: it ain’t the machine).

Also, you can think of programming as applied logic. Every once in a while, you’ll get to apply some logic - implement something in code - that is beautiful, elegant, and that no one else may ever see.

Worth it.

This is something that may be hard for many people to understand. If you ever take computer architecture, you’ll learn a little about how code work there.

Basically, what we write as coders the machine can’t interpret directly. We compile the code and the compiler converts our code into what the machine can understand: 1s and 0s. When we run the program, the processor then uses digital logic and math to figure out what the binary (machine language) is asking and to execute it.

I don’t know what you’re using to learn Python, but lots of books and websites that teach new languages assume you’re already a programmer.

I wish I had the same experience. For the most part when I was learning many languages it was always:
“Ok thiiiiis is a for loop. For loops work like this. Thiiiis is a comparison. Don’t confuse = and ==…” There was a lot of skimming unless I just read the documentation.

And for MandM093. It depends on what you’re environment is, i.e. if you’re on a coding website or on your desktop terminal. Essentially, after writing your code, your “run” it. Then a program that has already been written (compiler or interpreter), takes your code as input and outputs 1s and 0s to the computer processor which executes what you meant by the code.

I have been using CodeAcademy for learning Python. Thanks for all the answers, I have a somewhat better understanding about code now.

Python is a great beginning language to start out with; it has relatively clear syntax (i.e. and, or for conditionals), which makes it a good introductory language for Object Oriented programming.

As for your question, it’s all about logic. Your code is analyzed (a better term may be ‘complied’) and executed; for python, if you’re using Komodo Edit, for example, you would write your code in a Komodo Edit module, save it in a folder somewhere, and access the folder on your command prompt. Then you could do two things:

  1. If it's a script, run the script
  2. Activate the python IDE by inputing >>>python, then import your module. Associated functions, variables etc with the module are now at your disposal.

@MandM093 here’s a tip: think of Python (or any programming language, really) as a set of commands or instructions, and that you have to follow the rules when implementing a certain function. Every time you create a for loop, follow the correct syntax and indentation structure. (Note that many other languages don’t require indentation, but this is good practice anyways).

Also, note that many programming problems have multiple ways of solving them, and there might be a way to write a function that takes 10x less time.

I know guineagirl and eshkidd covered this briefly, but it’s a little difficult to explain to a first-time programmer. Essentially, every time you compile your Python code, the compiler processes the code into a lower-level machine language (for example, ALU operations on registers, or branch/jump operations) which are encoded in binary. Think of it like using these basic machine language instructions to make Python commands, then using those commands to build your own functions, then using those functions…you get the picture.