Master Python Basics: Variables, Control Flow, Loops, and Data Structures
This tutorial introduces Python as a high‑level, readable language, explains why it’s popular for web, data science and AI, and walks through core fundamentals such as variables, if/elif/else statements, while and for loops, lists, dictionaries, and iteration with clear code examples.
What Is Python?
According to its creator Guido van Rossum, Python is a high‑level programming language whose core design philosophy emphasizes code readability and concise syntax, allowing developers to express ideas with very few lines of code.
Many learners choose Python because it enables elegant programming and can be applied to data science, web development, machine learning, and more; companies like Quora, Pinterest and Spotify use it for backend development.
Python Fundamentals
1. Variables
Variables act as named containers for values.
one = 1 two = 2 some_number = 10000 # boolean
boolean_true = True
boolean_false = False # string
my_name = "Leandro Tk" # float
book_price = 15.80Any type of value can be assigned to any variable.
2. Control Flow – Conditional Statements
The if statement evaluates an expression; if it is true, the indented block runs.
if True:
print("Hello Python If")
if 2 > 1:
print("2 is greater than 1")If the condition is false, an optional else block runs. The elif clause adds additional checks.
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("2 is greater than 1")
else:
print("1 is equal to 2")3. Loops and Iteration
While loop repeats as long as its condition remains true.
num = 1
while num <= 10:
print(num)
num += 1Another example demonstrates a loop that runs until a flag becomes false.
loop_condition = True
while loop_condition:
print("Loop Condition keeps: %s" % (loop_condition))
loop_condition = FalseFor loop iterates over a sequence.
for i in range(1, 11):
print(i)4. Lists (Arrays)
Lists store ordered collections of values and support indexing.
my_integers = [1, 2, 3, 4, 5]
print(my_integers[0]) # 1
print(my_integers[4]) # 5Lists can hold any type, e.g., strings.
relatives_names = ["Toshiaki", "Juliana", "Yuji", "Bruno", "Kaio"]
print(relatives_names[4]) # KaioElements are added with append.
bookshelf = []
bookshelf.append("The Effective Engineer")
bookshelf.append("The 4 Hour Work Week")
print(bookshelf[0]) # The Effective Engineer
print(bookshelf[1]) # The 4 Hour Work WeekSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
