01 Aug 2024 by Ijeoma Jahsway
Category: Python Tutorials
Frameworks: Python
Read Time: 20 Minutes
Python, one of the most popular programming languages today, is known for its simplicity and versatility. In fact, it is so versatile that it is widely applied in fields like web development, data science, artificial intelligence, and automation, Python is perfect for newbies in programming, and this comprehensive guide is meant to walk you through the basics and help you build a strong foundation.
Before we start, let's understand why Python stands out:
To learn python, you'll need 240 IQ, a minimum of 50k in your account, and all the time you could squeezes out of your day... Just kidding ?, you only need a PC and internet connection. Easy right? Now let's jump into it.
First, you'll need to install Python on your computer. Python is available for all major operating systems, including Windows, macOS, and Linux.
python3 --version
. If you need to install or update Python, use your package manager. For example, on Ubuntu, you can use sudo apt-get install python3
.Official Python Website
An IDE can make your coding experience more pleasant and efficient, otherwise you could just run your code through your systems text editor. It's boring, but hey, it still works. The popular IDE's are:
Not sure which one to go with? That's fine, as a beginner, I'd advise you go with Visual Studio Code. It's very functional, user friendly and super easy to set up. And the best part is, you have extended support for whichever field or programming language you want to dive into.
Now that you have Python installed and your IDE set up, it's time to write some code. Open your IDE and create a new file. You can name it whatever you like, but let's start with "hello.py
". (The '.py' extension is important cuz that's how your system knows it's a python file. ) In this file, type the following code:
print("Hello, World!")
Save the file and run it (You could activate the auto save feature in VsCode by clicking the 'file' dropdown, and selecting Auto Save. When you're done, there should be a "Run" button, icon or option, click it to run your code. You can use VsCode terminal, but if you're using your systems terminal, whichever, navigate to the directory where your file is saved and type:
python3 hello.py
# Or py hello.py
You should see the output:
Hello, World!
Congratulations! You've just written and executed Python program. That's it. You're ready. Apply for jobs and conquer the corporate world. I mean it, go, you're done.
I'm joking again, c'mon, can't you take a joke? ? You still have allot more to learn if you really want to join the moving train, but don't worry, we'll take it one line of code at a time. Now lets move on. Try running the examples as we go along, so you see the results.
Variables are used to store data. Python supports various data types, including integers, floats, strings, and booleans. Think of variables as names given to specific data tpes or entire lines of logic. We'll get to that in a bit, Let's look into the various data types in Python.
# Integer (Simply a number without decimal points)
x = 5
print(x)
# Float (A number with decimal points)
y = 3.14
print(y)
# String (An alphabet, a text an entire sentence, or basically anything. As long as it is enclosed in quotes)
name = "Alice"
print(name)
# Boolean (Ah, the one and zero. Yes or No, Black or White. "True or False")
is_student = True
print(is_student)
Lists are used to store multiple items in a single variable. They are ordered and mutable (This means they can be changed). Hey, don't get intimated by these little terminologies, when you start coding python, you'll start using some of them yourself.
fruits = ["apple", "banana", "cherry"] # (Storing the list of fruits in a variable 'fruits')
print(fruits)
# Accessing an element in the list
print(fruits[0]) # apple
# (This is called indexing, we'll get to that later)
# Adding an element to the list
fruits.append("orange")
print(fruits)
# Removing an element from the list
fruits.remove("banana")
print(fruits)
Dictionaries store data in key-value pairs, you set a key, then you give that key a value. They are unordered and mutable. (Remember this term?)
person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person)
# Accessing values
print(person["name"]) # Alice
# Adding key-value pairs
person["email"] = "alice@example.com"
print(person)
# Removing key-value pairs
del person["age"]
print(person)
Loops allow you to execute a block of code repeatedly.
# For loop
for i in range(5):
print(i)
# This block of code will 'i' for whatever number of units are in the number 5
# While loop
count = 0
while count < 5:
print(count)
count += 1 # A short way of saying "Keep adding one to the present result"
# This block of code will keep displaying the word 'count' until the value of count reaches five
Functions are blocks of code that perform a specific task. They help make your code more modular and reusable. Meaning you can declare a function that performs a specific task and call it later in your code whenever you want to perform that task.
# Define a function
def greet(name):
print(f"Hello, {name}!")
# Call it later when you want to greet Alice and Bob
greet("Alice")
greet("Bob")
Keep on coding until you're comfortable with the basics.
The best way to learn programming is by doing. Now i know you already have some exciting things you want to try with what you've learned so far. Well go ahead. Don't be scared if you run into any error, just start over. The more you practice, the more you'll get comfortable with writing eack line of code.
Engage with the Python community through forums, social media, and local meetups. Sites like Stack Overflow, Reddit, and Python.org have active communities where you can ask questions, share knowledge, and collaborate with others.
Python is a powerful and beginner-friendly programming language that opens up a world of possibilities. By following this guide and practicing regularly, you'll be well on your way to becoming proficient in Python. Leave a comment to share insights or ask whatever questions you might have on the topic. We'll meet again later to cover more advanced topics in Python programming. Happy coding!
Subscribe to our Telegram Channel to get exclusive content and be the first to know when new blog posts go live! 🎉
#Python programming #Beginner programming guide #Learn Python #Python setup #Coding in Python #Python tutorial #Introduction to Python #Python development #Python for beginners #Python basics
Delta State, Nigeria