Master Python Basics: Variables, Loops, Data Structures, and OOP

This tutorial introduces Python's core philosophy and syntax, covering variables, conditional statements, loops, lists, dictionaries, and object‑oriented concepts such as classes, encapsulation, and inheritance, providing ready‑to‑run code examples for each topic.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Python Basics: Variables, Loops, Data Structures, and OOP

Python Basics

According to Guido van Rossum, Python is a high‑level language designed for readability, allowing programmers to express ideas with few lines of code. It is used for data science, web development, and machine learning.

Variables

Variables store values; examples:

one = 1
two = 2
some_number = 10000
# boolean examples
boolean_true = True
boolean_false = False
my_name = "Leandro Tk"
book_price = 15.80

Control Flow – Conditional Statements

if True:
    print("Hello Python If")
if 2 > 1:
    print("2 is greater than 1")
if 1 > 2:
    print("1 is greater than 2")
else:
    print("1 is not greater than 2")
if 1 > 2:
    print("1 is greater than 2")
elif 2 > 1:
    print("1 is not greater than 2")
else:
    print("1 is equal to 2")

Loops and Iteration

num = 1
while num <= 10:
    print(num)
    num += 1

loop_condition = True
while loop_condition:
    print("Loop Condition keeps: %s" % (loop_condition))
    loop_condition = False

for i in range(1, 11):
    print(i)

Lists – Collections

my_integers = [1, 2, 3, 4, 5]
print(my_integers[0])  # 1
relatives_names = ["Toshiaki", "Juliana", "Yuji", "Bruno", "Kaio"]
print(relatives_names[4])  # Kaio
bookshelf = []
bookshelf.append("The Effective Engineer")
bookshelf.append("The 4 Hour Work Week")
print(bookshelf[0])

Dictionaries – Key‑Value Data Structure

dictionary_example = {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3"
}

dictionary_tk = {
    "name": "Leandro",
    "nickname": "Tk",
    "nationality": "Brazilian"
}
print("My name is %s" % (dictionary_tk["name"]))

Iterating Over Dictionaries

for key in dictionary:
    print("%s --> %s" % (key, dictionary[key]))
for key, value in dictionary.items():
    print("%s --> %s" % (key, value))

Classes & Objects

class Vehicle:
    def __init__(self, number_of_wheels, type_of_tank, seating_capacity, maximum_velocity):
        self.number_of_wheels = number_of_wheels
        self.type_of_tank = type_of_tank
        self.seating_capacity = seating_capacity
        self.maximum_velocity = maximum_velocity

    @property
    def number_of_wheels(self):
        return self._number_of_wheels

    @number_of_wheels.setter
    def number_of_wheels(self, number):
        self._number_of_wheels = number

    def make_noise(self):
        print('VRUUUUUUUM')

Encapsulation

Encapsulation hides an object’s internal state and requires interaction through methods, using public and non‑public (prefixed with an underscore) attributes and accessor methods.

Inheritance

class Car:
    def __init__(self, number_of_wheels, seating_capacity, maximum_velocity):
        self.number_of_wheels = number_of_wheels
        self.seating_capacity = seating_capacity
        self.maximum_velocity = maximum_velocity

class ElectricCar(Car):
    def __init__(self, number_of_wheels, seating_capacity, maximum_velocity):
        super().__init__(number_of_wheels, seating_capacity, maximum_velocity)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OOPfundamentalsVariablesLoops
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.