Python is a general purpose language.... That's it, that's all I can say about it and honestly that's all you need to know in my opinion.
Some of its use cases are tied to data, AI & ML, backend systems, scripts, heck even some hacking scripts, malwares and Ransomware are also not impossible..... Basically a lot of things are buildable with python, but you should be aware of python limits and where you may need to learn other languages.
For example python is not good for low level coding which may involve memory and hardware manipulation, whereas C++ or C is perfect for such use case.
In any case just be aware of your limits with python and build within that frame, beyond that you're good.
Alright so what should we begin with.....
Let's start with the basics:
Variables:
Basically they are names(identifiers) that store data(values). That's it, in very simple terms.
An example is this:
name ="Juddy"
age = 18
And here's how you can declare a variable in another language:
let age = 18
const name = "ZAIDU"
age = 18 // this will most likely raise an error but you should get the gist from this
Sorry for adding JavaScript, even I don't know much about it, it's also kind of similar to my own language called Zexus so yeah that's that.
So those are variables, there are also other data types like lists, Boolean, dictionary, integers, floats, strings, tuple.... There are approximately 14 of them, but I have only been introduced to this much at this stage, So we will only be covering these.
Let's get into details then:
Lists are mutable collection of values, when you hear the word mutable it means the value can be changed after creation.
Here's an example of a list:
my_list = [1, 2, 3] # [1, 2, 3]
my_list.append(4) # this now becomes [1, 2, 3, 4]
A Boolean is a value that can either be true or false. it's just like binary where it's just 1s and 0s(but it's not binary so keep that in mind).
Anyways :
- True and False are their own types (bool).
- They behave like 1 and 0 in math, but they are not just numbers.
Better way to think about it:
Booleans represent decisions, not numbers.
Here's an example:
testing_bool = True
testing2 = False
An advanced version will be:
name = input("Type your name: ")
is_login = True
if is_login:
print(f"Welcome Boss {name}")
else:
print("You need to login in")
Oops, got carried Away there I won't break down everything for you but the explanation, if done correctly:
The code asks for an input, in this case your name.
Next it reads the is_login = True.
The "if" condition confirms is_login is Truthy, if that's the case it prints the message below, but if you were to change the value to False, then it will print the else message.
Alright let's continue.
Dictionaries are used to store values in key-pairs, I don't fully understand it myself, but here's an example:
my_dict = {"name": 'Joe', "friend": 'Jeena', "age": 19}
Integers are just whole numbers from 0 to any number, integers don't contain any dots(e.g 6.7).
Here's an example:
my_integer = 12
another = 13
print(my_integer, another) # 12 13
Floats are numbers that contain points or dots, as in not whole numbers.
It looks like this:
my_float = 3.9
another = 9.12
print(my_float, another) # 3.9 9.12
Strings are words/text enclosed in single or double quotes, it's recommended to always stick with one.
Example:
my_name = "Juddy"
sur_name = 'Unknown'
print(my_name, sur_name) # Juddy Unknown
And lastly from my knowledge we have tuples which are immutable ordered collections of data:
Example:
my_tuple = (1, 2, 3, 4)
It's worth noting that python is case sensitive, which means Main and main are two different variables.
What else can I recall after this...
Well there are other stuffs called built-ins, but we're not gonna dive into those here, instead we're gonna complete two more things.
The first is a quiz:
Try to guess what built-in I have been using in the examples, a hint: "It has appeared 5 times in total".
Secondly:
I should share with you the remaining keywords of python that I know of at the moment.
if/else conditions:
You must have noticed me using it in the examples, Well they're used to set a condition in which the code can either be True or False.
You can use this analogy:
A gateman who allows people who have an 8 digit license number, cars to pass. If the car owners have a license, then they are allowed to pass(True), and if not they should get a license first:
car = input("Input your car type: ")
license = int(input("Type your licence number: ")) # We will use numbers as an example.
if len(str(license)) == 8:
print("you can pass")
else:
print("You should get your license first")
This is just a small example.
Your homework will be to try and explain the code block above.
for/while
These are loops conditions, basically they can carry values and loop over sequence multiple times if the conditions match.
The "for" keyword can iterate over a sequence from start to finish.
As for "while" it loops across values until they become False (basically a type of retry command).
Here's an example of both in action:
numbers = [1, 3, 7, 0, 15]
for number in numbers:
count = number
while count > 0:
print(count)
count -= 1
Another thing you should know is reassignment, you can do it like these:
count = 1
count += 1 # count is now 2
counting = count # This creates a new variable(counting) and assign the value in count(2)
print(counting) # 2
"def" are used to contain codes into a single block, I consider this a container, this keywords also have specific rules when accessing code inside the container.
def the_name():
return "Hello World"
There are more of these keywords, but for now this is all I have from my head.
I hope you find this useful and understanding, you can search more online for things I wasn't able to explain properly.
Top comments (0)