Python Cheat Sheet Part 01 - Python Basics & Syntax
Welcome to Cyber Supto! I'm Supto, and in this Python Cheat Sheet series I will help you quickly learn Python with simple tips, examples, and practical notes. This series is designed for beginners and developers who want a quick reference while coding.
In this first part, we will cover Python basics, syntax, variables, data types, and simple operations. Think of this as the foundation for everything you will build in Python later.
What is Python?
Python is a powerful, beginner-friendly programming language used for:
- Web Development
- Automation
- Cybersecurity Tools
- Data Science
- Artificial Intelligence
- Software Development
Python is popular because its syntax is simple and easy to read.
Installing Python
Download Python from the official website and install it on your system.
- Visit: python.org
- Download the latest stable version
- During installation, enable "Add Python to PATH"
Check installation:
python --version
Your First Python Program
The traditional first program is printing a message:
print("Hello, World!")
This command outputs text to the screen.
Python Comments
Comments help developers understand code.
# This is a single line comment
"""
This is
a multi-line
comment
"""
Python Variables
Variables store values.
name = "Supto"
age = 20
is_student = True
Python automatically detects the variable type.
Variable Naming Rules
- Must start with a letter or underscore
- Cannot start with a number
- Use descriptive names
- Case sensitive
Basic Data Types
Python has several built-in data types.
- String – text data
- Integer – whole numbers
- Float – decimal numbers
- Boolean – True or False
name = "Cyber Supto"
age = 20
price = 9.99
is_online = True
Type Checking
You can check a variable's type using type().
x = 10
print(type(x))
Basic Operators
Arithmetic Operators
a = 10
b = 3
print(a + b) # addition
print(a - b) # subtraction
print(a * b) # multiplication
print(a / b) # division
print(a % b) # modulus
print(a ** b) # power
Comparison Operators
a = 5
b = 10
print(a == b)
print(a != b)
print(a > b)
print(a < b)
Logical Operators
x = True
y = False
print(x and y)
print(x or y)
print(not x)
Taking User Input
Python can take input from the user.
name = input("Enter your name: ")
print("Hello", name)
Type Conversion
Sometimes you need to convert data types.
age = input("Enter age: ")
age = int(age)
print(age + 5)
Common conversions:
- int()
- float()
- str()
- bool()
Quick Tips
- Use meaningful variable names
- Keep code readable
- Use comments to explain logic
- Practice writing small scripts daily
Next Parts of This Python Cheat Sheet
- Python Cheat Sheet Part 02 - Control Flow (If, Else, Loops)
- Python Cheat Sheet Part 03 - Functions & Modules
- Python Cheat Sheet Part 04 - Data Structures (Lists, Tuples, Sets, Dictionaries)
- Python Cheat Sheet Part 05 - Advanced Python & Best Practices
This Python Cheat Sheet series on Cyber Supto is designed to be a quick reference you can revisit anytime while learning or coding.
Thanks for reading,
Cyber Supto.
Post a Comment