Table of Contents
- Importing Modules
- If statement structure
Importing some modules is one of the most important things since without modules, most of the stuff will be undefined. To import a module, do:
Some common modules you can import is:
There are a lot more out there but I'm not going to cover those in this tutorial.
Now you know how to import modules. How do you import some files?
You may have noticed an add files button. If you don't want your code to be on the main.py, you could write some code on another file.
But if you run it, nothing will happen because you haven't imported that file to the main.py. In order to do that:
You don't need to include the .py in the file name. Also, the * means you imported everything in that file.
If you want to be more specific, do:
In order to organize or describe your code, you need comments. To make some comments. Add a hashtag
# before your code:
Of course the output won't write anything because a comment is just a comment. It won't affect the code.
All you learned up there 👆, didn't do anything when you executed the code. Now, we are going to print stuff out.
It's very simple.
In the quotation, is where you write the thing you want to say. But sometimes, you don't want the quotations to be there. The variables section will take about that more.
And...what do you know, this is the variables section. So...about that, you don't need quotations is because (wait let me first talk about what variables are.)
Variables are kind of a way to store value to a desired name.
If you do this, you have stored the value 2 into "x". Now when you
The output will be:
It wasn't x because we didn't have quotations. If we did, the output will be x. Since we literally printed "x" not x (which is 2)
Finally, the good stuff. Inputs ask the user to input something into the computer. If I said, what is your name?. And you typed in blablabla. The computer could store that in a variable. Let's see how this looks like in code:
If you input your name,:
It stored that in a variable called name. So if you printed that variable, it will print blablabla.
If statement structure
You know now how to ask the user questions. But what will happen after the user inputs it?
Isn't nice to have your own functions? To do that:
Notice how I indented the #What you want in here. It is a signal to your computer that lets it knows that it is a different line of code.
But it won't do anything until you call the function:
Then it will do whatever you put in it.
If you have any questions/feedback/concerns, post it in the comments section.
Bruuuuuuhhh why on earth did you start with modules lmao! Start with comments or a
Hello World! program!!
Also, you should probably add a bit more details like for example for functions (what they are exactly, what to use them for). Same thing for the conditionals and the
And maybe add arrays as well as exception handling? :)