Welcome to the world of programming! Python is one of the most beginner-friendly programming languages due to its simple and readable syntax. It is widely used in various fields, such as web development, data science, machine learning, and more.
If you're looking to start programming in another language, check out these guides:
Before you can start writing Python code, you need to set up your environment. Here's how to get started:
pip install notebook
.Open your code editor or Python interpreter (you can run python
in your terminal), and try this code:
print("Hello, World!") # Output: Hello, World!
This simple line of code displays the text Hello, World! in the console. Congratulations, you've just written your first Python program!
Variables in Python store data. Here's an example:
name = "Alice" # String age = 30 # Integer is_student = True # Boolean
Python has the following basic data types:
"Hello"
)10
)3.14
)True
or False
)[1, 2, 3]
){"name": "Alice", "age": 30}
)Functions are blocks of reusable code. You can define a function in Python like this:
def greet(name): return f"Hello, {name}!" print(greet("Alice")) # Output: Hello, Alice!
Python's if-else
statement allows you to execute code based on conditions. For example:
age = 20 if age >= 18: print("You are an adult.") else: print("You are a minor.")
This code checks if age
is greater than or equal to 18 and prints a message accordingly.
Loops let you repeat actions. For example, a for
loop can iterate through a range of numbers:
for i in range(5): print(i) # Output: 0, 1, 2, 3, 4
Now that you've learned the basics, here are some next steps:
Happy coding! 🎉