Skip to content
Sign upLog in
← Back to Community

🐍Python-The Basics💻

Profile icon

🐍Python-The Basics💻

Table of Contents

  • Importing Modules
  • Comments
  • Printing
  • Variables
  • If statement structure
  • Functions

Importing Modules

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:

import module_name

Some common modules you can import is:

  • turtle
  • sys
  • os
  • random
  • pygame
  • math

There are a lot more out there but I'm not going to cover those in this tutorial.

Moving on

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, 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 In order to do that:

from file_name import *

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:

from file_name import a variable/function_name


In order to organize or describe your code, you need comments. To make some comments. Add a hashtag # before your code:

#This is a comment


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.

print("Hello World!")

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.

x = 2

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:

name = input("What is your name?")

If you input your name,:

>>> blablabla

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?

# If this condition meets, do this: if name == "XThacker": print("Hello administrator!") # If this condition meets, do this: elif name == "HIHI": print("HI to you too!") # Anything other than the if and elif, do this: else: print(f"Hello {name}") # We won't cover f-strings in this tutorial


Isn't nice to have your own functions? To do that:

def my_function(): # What you want in here

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.

Until then,


Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon

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 input() function.

And maybe add arrays as well as exception handling? :)

Profile icon

the hello world program is so simple its just print("Hello World!") and only people who uses programming less does that so

Profile icon

well it’s still useful to know lol. Some people who might’ve never done Python might not know how to output.

Profile icon

OK so there's a spelling error:


it should be "there are" not "they're".
sorry for being an English teacher
I like the tutorial nonetheless!

Profile icon

np for being an English teacher And fixed. Thanks too for liking it.