How to LEARN PYTHON the COOLJAMES way (Lesson 1 - Sequence)
Hello guys!
Welcome to another
@CoolJames1610 tutorial :P :P :PNow, I am going to teach you how to PYTHON the COOLJAMES way (which is cool)
Lesson 1 - Sequences
So, the first lesson will be about sequences.
But first let's go over some key terms.
- Declaring variables.
Unlike other PL's, in Python you do not need to add BOOL, or STR, or INT before you declare a variable. Python automatically knows which data type you enter in.
Example:
x = 0 #Integer x = "Hey" #String x = True #Boolean
- Artithmetic
Arithmetic is mainly the same across PL's.
x = 5 + 5 y = x + 10 z = x * y
- Keywords
These are a few of the keywords in Python. You cannot declare these variables
import from as and not in print
etc... I can't remember all xD
Okay, I think that is all for the basics, now onto sequences...
A sequence is just commands all after each other
Example
print("Hello World") x = "James" print("Hello " + x)
So in this program, Python will output 'Hello World', then assign '"James"' to x and then out put 'Hello" added with the value attached to x
Python is quite simple xD
Now let's move onto input from the user.
All you have to do to get input from the user is:
x = input()
This will prompt your user to enter something.
Now this wouldn't be very helpful as nothing is telling the user to input something.
We can add text to the input
x = input("Please enter your name: ")
As you can see, I have left a space after the colon. This is better to do as the program will look neater.
This:
Please enter your name: James or Please enter your name James
Instead of:
Please enter your name:James or Please enter your nameJames
See? :D Much neater :P
I'm tired of people not adding a space or something lol
Okay now, I'll talk briefly about concatenation.
This is combining different data types together.
Say I asked the user for their age and I wanted to say: "Oh nice, I am also " (user's age), most people may just do:
x = input("Please enter your age: ") print("Oh nice, I am also " + x)
Here we would get an error.
In Python, if you are outputting to the screen, everything has to be the same data type.
"Oh nice, I am also" is a string
x is an integer.
To get round this problem, we can cast
x to a string so that we can use it to say something.
All we need to do is str(x)
. This changes x to a string and can be used.
x = input("Please enter your age: ") print("Oh nice, I am also " + str(x))
Ahaha no error ;)
We can cast a string to an integer but only if it is a whole number (e.g. not a decimal)
x = "10" e = 34 * int(x) print(e)
Here, x is a whole number so we can cast it as an integer.
(Would output 340 in case you wanted it :P)
There are also the bool
and float
casters.
I think that is it for today's tutorial
I know this isn't good and not in depth but I DON'T CARE xD
This is how I kinda learnt Python and I've learnt a lot xD
Erm, please upvote so that amasd can comment again people can see and learn :)
Lesson 2 will be about Selection (if, elif, else)
Thanks again,
@CoolJames1610
im surpised you didnt talk about
print
in the beginning of the tutorial.also you forgot the mandatory
print ("Hello World!")
my way
not the default wayLol yea
@CoolJames1610