Introduction to Python: Variables, Data Types, and Print Function

Hello everyone! This is the first article in the Python introductory series, where we focus on the three most fundamental and critical concepts: variables, data types, and the print function. The content has been streamlined to retain only the core usage and key points to avoid pitfalls, making it easy for beginners to understand and practice quickly, helping you take a solid first step into learning Python.

1. Variables: “Little Boxes” for Storing Data

1. Core Usage

Syntax:variable_name = value(Assignment is definition, no type specification needed)

Example:

name = "小明"  # Store name
age = 18        # Store age
score = 90.5   # Store score

2. Three Naming Rules to Remember · Only letters, numbers, and underscores are allowed, and cannot start with a number (e.g.user123is valid,123useris invalid) · Case-sensitive (Name and name are two different variables) · Do not use Python keywords (e.g.if,for,True cannot be used as variable names)

2. Five Basic Data Types (with Usage)

Type

Description

Example

Integer (int)

Whole numbers without decimals

count = 10

Float (float)

Numbers with decimals

price = 29.9

String (str)

Text enclosed in single/double quotes

title = “Python课”

Boolean (bool)

Only two values: True/False

is_pass = True

NoneType (None)

Represents “no value”

avatar = None

Check type:Usetype()

print(type(age))    # Output: <class 'int'> (Check the type of age)
print(type(score))  # Output: <class 'float'> (Check the type of score)

3. Print Function: The “Tool” to View Results

1. Basic Usage

print("你好")        # Print text, output: 你好
print(name)          # Print variable, output: 小明
print("年龄:", age) # Print text and variable together, output: 年龄:18

2. Practical Tips

· Formatted output (concise information display):

print(f"名字:{name},分数:{score}")  # Output: 名字:小明,分数:90.5

· Cancel automatic line break (Addend=””):

print("Hello", end=" "); print("Python")  # Output: Hello Python

4. Quick Practice

# 1. Define variables
user_name = "小红"
user_age = 19
is_student = True
# 2. Print results
print(f"用户:{user_name},年龄:{user_age},是否学生:{is_student}")

Run output:用户:小红,年龄:19,是否学生:True

Next Issue Preview

Next time we will discuss “Python Operators”, teaching you how to perform simple calculations using addition, subtraction, multiplication, and division. Stay tuned!

Leave a Comment