MindMap Gallery Python basics(2)
This is a mind map about the basic knowledge of Python (2), including basic syntax, basic data types, type conversion, common operators, and structured programming design.
Edited at 2024-11-25 15:57:05This template shows the structure and function of the reproductive system in the form of a mind map. It introduces the various components of the internal and external genitals, and sorts out the knowledge clearly to help you become familiar with the key points of knowledge.
This is a mind map about the interpretation and summary of the relationship field e-book, Main content: Overview of the essence interpretation and overview of the relationship field e-book. "Relationship field" refers to the complex interpersonal network in which an individual influences others through specific behaviors and attitudes.
This is a mind map about accounting books and accounting records. The main contents include: the focus of this chapter, reflecting the business results process of the enterprise, the loan and credit accounting method, and the original book of the person.
This template shows the structure and function of the reproductive system in the form of a mind map. It introduces the various components of the internal and external genitals, and sorts out the knowledge clearly to help you become familiar with the key points of knowledge.
This is a mind map about the interpretation and summary of the relationship field e-book, Main content: Overview of the essence interpretation and overview of the relationship field e-book. "Relationship field" refers to the complex interpersonal network in which an individual influences others through specific behaviors and attitudes.
This is a mind map about accounting books and accounting records. The main contents include: the focus of this chapter, reflecting the business results process of the enterprise, the loan and credit accounting method, and the original book of the person.
Python basics
basic grammar
Indentation: Python uses indentation to represent blocks of code instead of braces like other languages. For example, when defining functions, conditional statements, and loop statements, the indented content belongs to the same code block. Annotation: There are two ways to annotate. Single-line comments use "#", and the content starting from "#" to the end of the line is a comment; multi-line comments use triple quotes (''' or """) to wrap the content that needs to be commented. End of statement: Generally, there is one statement per line, and a semicolon is not required at the end of the statement. However, if you want to write multiple statements in one line, you can separate them with semicolons.
Basic data types
Numerical type Integer type (int): represents an integer, such as 1, -5, 100, etc. In Python 3, integers have no size limit, as long as memory allows. Float: represents decimals, such as 3.14, -2.5, etc. Scientific notation can be used, such as 1.23e-4 for 0.000123. String (str): A sequence of characters wrapped in single quotes ('), double quotes ("), or triple quotes (''' or """). For example, 'hello', "world", '''This is a multi-line string Can span multiple lines '''. Boolean type (bool): There are only two values, True (true) and False (false), used for logical judgment.
type conversion
Implicit conversion: In certain operations, Python will automatically perform type conversion. For example, when integers and floating point numbers are added, the integers are automatically converted to floating point numbers and then the operation is performed. Explicit conversion: performed through functions, such as int() can convert a string or floating point number that conforms to the integer format into an integer (floating point number conversion will truncate the decimal part), float() converts other types into floating point numbers, str( ) to convert other types to strings.
Common operators
Arithmetic operators: addition ( ), subtraction (-), multiplication (*), division (/), integer division (//, returns the integer part of the quotient), remainder (%), exponentiation (**). Relational operators: greater than (>), less than (<), equal to (==), greater than or equal to (>=), less than or equal to (<=), not equal to (!=), the operation result is a Boolean value. Logical operators: and (and), or (or), not (not), used to combine logical condition judgments. Assignment operator: The basic assignment is "=", and there are also compound assignment operators, such as = (a = 1 is equivalent to a = a 1), -=, *=, etc.
structured programming
- Sequential structure: The code is executed in order from top to bottom. This is the most basic program execution flow. - Select structure - if statement: The format is if condition: statement block. When the condition is true, the statement block is executed. Else and elif can be added to achieve more branch judgments. For example: python if score >= 90: print("Excellent") elif score >= 60: print("passed") else: print("failed") - Ternary expression: It is a shorthand form of a simple if-else statement, such as result = "Yes" if a > 10 else "No". - Loop structure - for loop: usually used to traverse iterable objects (such as lists, strings, etc.). For example: python fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) - while loop: When the condition is true, the statement block is executed in a loop. For example: python count = 0 while count < 5: print(count) count = 1