Side-by-side programming tutorials for beginners.
Assign data to variables dynamically without declaring types.
name = "Alice"
print(f"Hello, {name}!")
Use indentation to structure execution based on boolean logic.
age = 18
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Iterate over ranges or run a block until a condition changes.
# For loop
for i in range(3):
print(f"Count: {i}")
# While loop
count = 0
while count < 3:
print(count)
count += 1
Define reusable tasks using the "def" keyword.
def greet(username):
return f"Welcome back, {username}!"
message = greet("Bob")
print(message)
Store items in ordered collections that dynamically resize.
fruits = ["apple", "banana", "cherry"]
# Append item
fruits.append("orange")
# Loop through list
for fruit in fruits:
print(fruit)
Explicitly define static types and end lines with semicolons.
#include <iostream>
#include <string>
int main() {
std::string name = "Alice";
std::cout << "Hello, " << name << "!" << std::endl;
return 0;
}
Enclose evaluation terms inside parentheses and operational tasks inside braces.
#include <iostream>
int main() {
int age = 18;
if (age >= 18) {
std::cout << "You are an adult." << std::endl;
} else {
std::cout << "You are a minor." << std::endl;
}
return 0;
}
Initialize variables, conditions, and increments explicitly inside structural statements.
#include <iostream>
int main() {
// For loop
for (int i = 0; i < 3; i++) {
std::cout << "Count: " << i << std::endl;
}
// While loop
int count = 0;
while (count < 3) {
std::cout << count << std::endl;
count++;
}
return 0;
}
Declare signature function return types prior to operational code routines.
#include <iostream>
#include <string>
std::string greet(std::string username) {
return "Welcome back, " + username + "!";
}
int main() {
std::string message = greet("Bob");
std::cout << message << std::endl;
return 0;
}
Utilize size-flexible standard library Vectors instead of basic fixed arrays.
#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<std::string> fruits = {"apple", "banana", "cherry"};
// Append item
fruits.push_back("orange");
// Loop through vector
for (const std::string& fruit : fruits) {
std::cout << fruit << std::endl;
}
return 0;
}