In Python, variables are containers with labels that hold whatever data you want—text, numbers, lists, you name it. You don’t need to tell Python what type of data is in there; it just goes with the flow.
Example:
name = "Alice" age = 25 height = 5.5
Here, name is a string, age is an integer, and height is a float. Now you can store info without getting bogged down in type declarations.
Python data types cover pretty much all your needs:
You’ve got your arithmetic operators ( , -, *, /), but Python’s also got some extras:
Examples:
a = 10 b = 3 print(a + b) # Addition print(a ** b) # Exponentiation (fancy word for power) print(a // b) # Floor division (cuts off decimals)
Here’s a quick profile check: if the age falls between 18 and 60 and the user’s an admin, they get access.
age = 30 is_admin = True if 18 <= age <= 60 and is_admin: print("Access Granted") else: print("Access Denied")
There you go!
As a wise coder once said, "May your bugs be few and your syntax be clean."
The above is the detailed content of Python Basics: Variables, Data Types, and Basic Operators. For more information, please follow other related articles on the PHP Chinese website!