MindMap Gallery Learning Artificial Intelligence Programming Python's main syntax and examples
This is a mind map about PYTHON, Main content: input, data structure comparison, reading, judgment, operation, dictionary, loop, array, space, variable, type, print.
Edited at 2025-02-06 11:35:30In order to help everyone use DeepSeek more efficiently, a collection of DeepSeek guide mind map was specially compiled! This mind map summarizes the main contents: Yitu related links, DS profile analysis, comparison of DeepSeek and ChatGPT technology routes, DeepSeek and Qwen model deployment guide, how to make more money with DeepSeek, how to play DeepSeek, DeepSeek scientific research Application, how to import text from DeepSeek into MindMaster, the official recommendation of DeepSeek Wait, allowing you to quickly grasp the essence of AI interaction. Whether it is content creation, plan planning, code generation, or learning improvement, DeepSeek can help you achieve twice the result with half the effort!
This is a mind map about DeepSeek's 30 feeding-level instructions. The main contents include: professional field enhancement instructions, interaction enhancement instructions, content production instructions, decision support instructions, information processing instructions, and basic instructions.
This is a mind map about a commercial solution for task speech recognition. The main content includes: text file content format:, providing text files according to the same file name as the voice file.
In order to help everyone use DeepSeek more efficiently, a collection of DeepSeek guide mind map was specially compiled! This mind map summarizes the main contents: Yitu related links, DS profile analysis, comparison of DeepSeek and ChatGPT technology routes, DeepSeek and Qwen model deployment guide, how to make more money with DeepSeek, how to play DeepSeek, DeepSeek scientific research Application, how to import text from DeepSeek into MindMaster, the official recommendation of DeepSeek Wait, allowing you to quickly grasp the essence of AI interaction. Whether it is content creation, plan planning, code generation, or learning improvement, DeepSeek can help you achieve twice the result with half the effort!
This is a mind map about DeepSeek's 30 feeding-level instructions. The main contents include: professional field enhancement instructions, interaction enhancement instructions, content production instructions, decision support instructions, information processing instructions, and basic instructions.
This is a mind map about a commercial solution for task speech recognition. The main content includes: text file content format:, providing text files according to the same file name as the voice file.
PYTHON
Quotes are string output
print("3*2") output is 3*2
Output without quotes
print(3*2) output result is 6
print(5**10) 5 to the power of 10 // It is the prescription
Three quotes allow line breaks
print(f"this is 3X2 result:{3 * 2} ") This is 3X2 result:6
print("this is 3X2 result:{3 * 2} ") this is 3X2 result:{3 * 2}
f: There is a special format {}: The inside is not affected by double quoted string types
type
The type() function is a built-in function, mainly used to return the type of an object, helping developers understand the data types of variables, objects, etc. during the programming process, so as to perform appropriate operations and processing.
int integer str string floats with decimal number list list bool logic true or false
type("2.8") returns str
type(2.8) returns floats
variable
The name of the variable cannot have spaces
age = 3 * 5 print(f"le age: {age}") le age: 15
Array
number = ["1", "2", "3"] print(f"this is {numberr}") this is ['1', '2', '3']
[ ] Represents an array
number = ["1", "2", "3"] print(f"this is {number[0]}") this is 1
Call a number in the array individually and count from 0
number= ["1", "2", "3"] number.append("4") print(number) ['1', '2', '3', '4']
Add an array
dictionary
dictionary refers to a dictionary. Each key-value pair consists of a key and the associated value (value). The key and value are separated by colon:, and the different key-value pairs are separated by commas, The entire dictionary is wrapped in curly braces {}.
Create a dictionary
# Create a dictionary containing three key-value pairs person = {"name": "Alice", "age": 25, "city": "New York"}
# Create a dictionary through keyword parameters student = dict(name="Bob", grade=80) # Create a dictionary from a list containing a tuple of key-value pairs colors = dict([("red", 1), ("green", 2), ("blue", 3)])
Visit the dictionary
person = {"name": "Alice", "age": 25, "city": "New York"} print(person["name"]) # Output: Alice
print(person) outputs all dictionaries
Modify the dictionary
person = {"name": "Alice", "age": 25} # Add elements person["city"] = "New York" # Modify elements person["age"] = 26 print(person) # Output: {'name': 'Alice', 'age': 26, 'city': 'New York'}
Delete elements
person = {"name": "Alice", "age": 25, "city": "New York"} del person["city"] print(person) # Output: {'name': 'Alice', 'age': 25}
Data structure comparison
List
is a variable ordered sequence, represented by square brackets [].
my_list = [1, 2, 3, 4] my_list.append(5)
Tuple (Tuple)
is an immutable ordered sequence, represented by parentheses ().
my_tuple = (1, 2, 3)
Dictionary
is an unordered set of key-value pairs, represented by curly braces {}
my_dict = {"name": "Alice", "age": 20} print(my_dict["name"])
Set (Set)
is a collection of unordered and unique elements, created with curly braces {} or set() functions.
my_set = {1, 2, 3, 3} print(my_set)
Spaces
age = 10 if age >= 18: # Indented code is executed when the condition is true print("You can smoke") print("You can drink") You can drink
Spaces are very important and represent the scope of function function.
judge
a = 1 b = 2 if a > b : print("a is big") else: print("b is big") print("this is result") b is big This is result
if: else:
score = 85 if score >= 90: print("Excellent") elif score >= 80: print("good") elif score >= 60: print("pass") else: print("Failed")
elif: Allows multiple condition branches to be added after an if statement. The program will check each elif condition in turn. Once a condition is true, the corresponding code block will be executed and the subsequent elif or else conditions will no longer be checked.
else: used to deal with all cases where the previous if and elif conditions are not met. It does not require specifying additional conditions, as long as all previous conditions are false, the contents in the else code block will be executed.
cycle
number_list=["1", "2", "3", "4"] for number in number_list: print(f"this is {number}") this is 1 this is 2 This is 3 This is 4
for in statement loop execution
number_list = ["1", "2", "3", "4"] for index, number in enumerate(number_list, start=1): print(f"{index} is {number}") The first one is 1 The second one is 2 The third one is 3 The fourth one is 4
enumerate: index of the sequence. index is an index value generated by the enumerate() function
number_list = ["1", "2", "3", "4"] for index, number in enumerate(number_list): if index == 2: number_list[index] = "Modified value" print(number_list) ['1', '2', 'Modified value', '4']
Index values are very important and can trigger an operation at a certain location.
== is a comparison operator
Operation
Comparison operator
a = 1 b = 2 print(a>b) False
== Determine whether the two values are equal 5 == 3 The result is False != Determine whether the two values are not equal 5 != 3 The result is True > Determine whether the value on the left is greater than the value on the right 5 > 3 The result is True < Determine whether the value on the left is smaller than the value on the right 5 < 3 The result is False >= Determine whether the value on the left is greater than or equal to the value on the right 5 >= 3 The result is True <= Determine whether the value on the left is less than or equal to the value on the right 5 <= 3 The result is False
# Prompt the user to enter an integer number = int(input("Please enter an integer: ")) # Determine whether the integer is an even number if number % 2 == 0: print(f"{number} is an even number.") else: print(f"{number} is an odd number.")
== Can be used for password verification, etc.
Arithmetic operators
Addition, used to add or splice two numbers 5 3 The result is 8; "Hello " "World" The result is "Hello World" - Subtraction, used to subtract two numbers 5 - 3 The result is 2 * Multiplication, used to multiply two numbers or repeat sequences 5 * 3 The result is 15; "abc" * 3 The result is "abcabcabc" / division, return floating point result 5 / 3 The result is 1.66666666666666666666667 // Divide, return the integer part of the quotient 5 // 3 The result is 1 % Take the modulus and return the remainder of the division 5 % 3 The result is 2 ** Power operation, calculate the specified power of a number 5 ** 3 The result is 125
Logical operators
a = 1 b = 2 print((a or b) >1) False
and logic and, the result is True only if both conditions are True or Logical or, as long as there is a condition that is True, the result is True Not logically non-referenced to the condition not (5 > 3) The result is False
Member operators
in If the value is in a sequence, set, or dictionary (judgment key), return True 3 in [1, 2, 3] The result is True not in If the value is not in a sequence, set, or dictionary (judgment key), return True 4 not in [1, 2, 3] The result is True
Identity operator
is Determine whether two objects are the same object a = [1, 2]; b = a; a is b The result is True is not to determine whether two objects are not the same object a = [1, 2]; b = [1, 2]; a is not b The result is True
Read
# Open the file file = open('example.txt', 'r', encoding='utf-8') # Read the entire file content content = file.read() print(content) # Close the file file.close()
After reading, use it with the closed file to free up memory
with open('example.txt', 'r', encoding='utf-8') as file: content = file.read() print(content)
Use with more in actual work, and you can automatically close it after reading it.
try: with open('example.txt', 'r', encoding='utf-8') as file: content = file.read() print(content) except FileNotFoundError: print("File not found, please check the file path.")
If the file does not exist, a FileNotFoundError exception will be thrown. This exception can be caught and handled using the try-except statement.
enter
# Prompt the user to enter a name name = input("Please enter your name: ") # Output greeting print(f"Hello, {name}! Welcome to learn Python.")
The input() function is used to get input from the user and return the contents entered by the user as a string.
# Prompt the user to enter the first number num1 = float(input("Please enter the first number: ")) # Prompt the user to enter the second number num2 = float(input("Please enter the second number: ")) # Calculate the sum of two numbers sum_result = num1 num2 # Output calculation results print(f"{num1} and {num2} sum is: {sum_result}")
The float() function converts the string entered by the user into a floating point number for numerical calculations.