Python Tutorial for Newbies
Here is a basic tutorial for Python, for beginners!
Table of Contents:
1. The developer of python
3. Print and input statements
- f' strings
4. If, Elif, Else statements
5. Common Modules
1. Developer of Python
It was created in the late 1980s by Guido van Rossum in the Netherlands. It was made as a successor to the ABC language, capable interfacing with the Ameoba operating system. It's name is python because when he was thinking about Python, he was also reading, 'Monty Python's Flying Circus'. Guido van Rossum thought that the langauge would need a short, unique name, so he chose Python.
For more about Guido van Rossum, click here
Comments are side notes you can write in python. They can be used, as I said before:
- instructions or steps
How to write comments:
The output is nothing because:
- It is a comment and comments are invisible to the computer
- Comments are not printed in Python
So just to make sure, hastags are used to make comments. And remember, comments are ignored by the computer.
3. Print and Input statements
1. Print Statements
Print statements, printed as
print, are statements used to print sentences or words. So for example:
The output would be:
So you can see that the
print statement is used to print words or sentences.
2. Input Statements
Input statements, printed as
input, are statements used to 'ask'. For example:
The output would be:
inputs, you can write in them. You can also 'name' the
input. Like this:
You could respond by doing this:
So pretty much, inputs are used to make a value that you can make later.
Then you could add a
if statement, but lets discuss that later.
3. f strings
f strings, printed as
f(before a qoutation), is used to print or input a value already used. So what I mean is, say I put an
f string on a print statement. Like this:
The output right now, is nothing. You didn't print anything. But say you add this:
It would work, only if the
name was named. In other words, say you had a
input before and you did this to it:
f string would work. Say for the input, you put in your name. Then when the print statement would print:
Another way you could do this is with commas. This won't use an f string either. They are also simaler. So how you would print it is like this:
The output would be the same as well! The commas seperate the 2 strings and they add the name inside. But JBYT27, why not a plus sign? Well, this question you would have to ask Guido van Rossum, but I guess I can answer it a bit. It's really the python syntax. The syntax was made that so when you did a plus sign, not a comma, it would give you an error.
Really, the only time you would use this is to give back your name, or to find if one value was equal to each other, which we'll learn in a sec.
4. If, Elif, Else Statements
1. If Statements
If statements, printed as
if, are literally as they are called, if sentences. They see if a sentence equals or is something to an object, it creates an effect. You could think an
if statement as a cause and effect. An example of a
if statement is:
The output could be:
However, say it isn't JBYT27. This is where the else, elif, try, and except statements comes in!
2. Elif Statements
Elif statements, printed as
elif are pretty much
if statements. It's just that the word
if are combined. So say you wanted to add more
if statements. Then you would do this:
It's just adding more
if statements, just adding a
else to it!
3. Else Statements
Else statments, printed as
else, are like
elif statements. They are used to tell the computer that if something is not that and it's not that, go to this other result. You can use it like this (following up from the other upper code):
5. Common Modules
Common modules include:
So all these modules that I listed, i'll tell you how to use, step by step! ;) But wait, what are modules?
Modules are like packages that are pre-installed in python. You just have to fully install it, which is the module(please correct me if im wrong). So like this code:
When you do this, you successfully import the
os module! But wait, what can you do with it? The most common way people use the
os module is to clear the page. By means, it clears the console(the black part) so it makes your screen clear-er. But, since there are many, many, many modules, you can also clear the screen using the
replit module. The code is like this:
But one amazing thing about this importing is you can make things specific. Like say you only want to import
sqrt from the
math package. This is the code:
Let me mention that when you do this, never, ever add an and. Like
from ... import ... and ....
That is just horrible and stupid and... Just don't do it :)
Next is the
You can use the time module for:
- time delay
- scroll text
And yeah, that's pretty much it (i think)
All of the import syntax is the same except for the names
Next is tkinter, turtle
You can use the
tkinter module for GUI's (screen playing), you can import it in a normal python, or you can do this in a new repl.
You can use the turtle for drawing, it isn't used much for web developing though.
The math and sys
The math is used for math calculations, to calculate math. The sys is used for accessing used variables. I don't really know how I could explain it to you, but for more, click here
random module is used for randomizing variables and strings. Say you wanted to randomize a list. Here would be the code:
The output would be a random choice from the variable/list. So it could be pie, JBYT27, cat, or dog. From the random module, there are many things you can import, but the most common are:
And that's all for modules. If you want links, click below.
Links for modules:
And that's it!
- Many coders for tutorials
- Books and websites
ranging from a few days or hours
if you like reading
You are a
I hope you enjoyed this tutorial! I'll cya on the next post!
stay safe and stay home :D!
I hope u got ur vaccine!