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.
<code>one = 1</code> <code>two = 2</code> <code>some_number = 10000</code> <code># boolean
boolean_true = True
boolean_false = False</code> <code># string
my_name = "Leandro Tk"</code> <code># float
book_price = 15.80</code>Any 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.
<code>if True:
print("Hello Python If")
if 2 > 1:
print("2 is greater than 1")</code>If the condition is false, an optional else block runs. The elif clause adds additional checks.
<code>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")</code>3. Loops and Iteration
While loop repeats as long as its condition remains true.
<code>num = 1
while num <= 10:
print(num)
num += 1</code>Another example demonstrates a loop that runs until a flag becomes false.
<code>loop_condition = True
while loop_condition:
print("Loop Condition keeps: %s" % (loop_condition))
loop_condition = False</code>For loop iterates over a sequence.
<code>for i in range(1, 11):
print(i)</code>4. Lists (Arrays)
Lists store ordered collections of values and support indexing.
<code>my_integers = [1, 2, 3, 4, 5]
print(my_integers[0]) # 1
print(my_integers[4]) # 5</code>Lists can hold any type, e.g., strings.
<code>relatives_names = ["Toshiaki", "Juliana", "Yuji", "Bruno", "Kaio"]
print(relatives_names[4]) # Kaio</code>Elements are added with append .
<code>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 Week</code>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.