Introduction
Python is one of the most popular programming languages in the world. It is known for its readability and versatility, making it an excellent choice for beginners. In this article, I will walk you through the basics of Python.
1. Why Python?
- Simple Syntax: Python's code looks like plain English.
- Large Community: You can easily find solutions to any problem online.
- Broad Applications: Used in Web Development, Data Science, AI, and Automation.
2. Setting Up
To start coding, you need to install Python from python.org.
Once installed, you can check the version by running this command in your terminal:
python --version
3. The Basics
Hello World
The classic first step in any language:
print("Hello, Qiita!")
Variables and Data Types
In Python, you don't need to declare types explicitly.
name = "Alice" # String
age = 25 # Integer
is_student = True # Boolean
height = 165.5 # Float
Control Flow (If-Else)
score = 85
if score >= 80:
print("Great job!")
else:
print("Keep trying!")
Loops
Iterating through a list is straightforward:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I like {fruit}")
4. Functions
Functions help you reuse code and keep it organized.
def greet(user_name):
return f"Hello, {user_name}!"
message = greet("Qiita User")
print(message)
Conclusion
Python is a powerful yet simple language. The best way to learn is by writing code every day. In the next post, I will cover more advanced topics like Classes and Modules.
Happy Coding!