This article does not have a corresponding language version
New version found
The website seems to have new content, do you want to update?
孤筝の温暖小家
素月分辉,明河共影,表里俱澄澈。
2023-06-272023-06-271546 words8 mins
Python Data Types and Operators
### Data Types
Python has several built-in data types, categorized as follows:
1. **Numeric Types**
- `int`: Integer (e.g., `5`, `-3`, `0`)
- `float`: Floating-point number (e.g., `3.14`, `-0.001`, `2.0`)
- `complex`: Complex number (e.g., `1 + 2j`, `3 - 4j`)
2. **Sequence Types**
- `str`: String (e.g., `"hello"`, `'Python'`)
- `list`: Mutable sequence (e.g., `[1, 2, 3]`, `['a', 'b', 'c']`)
- `tuple`: Immutable sequence (e.g., `(1, 2, 3)`, `('x', 'y', 'z')`)
3. **Mapping Type**
- `dict`: Key-value pairs (e.g., `{'name': 'Alice', 'age': 25}`)
4. **Set Types**
- `set`: Unordered, unique elements (e.g., `{1, 2, 3}`)
- `frozenset`: Immutable set (e.g., `frozenset({1, 2, 3})`)
5. **Boolean Type**
- `bool`: Logical values (`True` or `False`)
6. **Binary Types**
- `bytes`: Immutable byte sequence (e.g., `b'hello'`)
- `bytearray`: Mutable byte sequence
- `memoryview`: Memory view of objects
### Operators
Python supports various operators for performing operations on data:
1. **Arithmetic Operators**
- `+` (Addition)
- `-` (Subtraction)
- `*` (Multiplication)
- `/` (Division)
- `%` (Modulus)
- `**` (Exponentiation)
- `//` (Floor Division)
2. **Comparison Operators**
- `==` (Equal)
- `!=` (Not Equal)
- `>` (Greater Than)
- `<` (Less Than)
- `>=` (Greater Than or Equal)
- `<=` (Less Than or Equal)
3. **Logical Operators**
- `and` (Logical AND)
- `or` (Logical OR)
- `not` (Logical NOT)
4. **Assignment Operators**
- `=` (Assignment)
- `+=`, `-=`, `*=`, `/=`, etc. (Compound Assignment)
5. **Bitwise Operators**
- `&` (AND)
- `|` (OR)
- `^` (XOR)
- `~` (NOT)
- `<<` (Left Shift)
- `>>` (Right Shift)
6. **Membership Operators**
- `in` (Checks if a value exists in a sequence)
- `not in` (Checks if a value does not exist in a sequence)
7. **Identity Operators**
- `is` (Checks if two variables refer to the same object)
- `is not` (Checks if two variables refer to different objects)
### Example Code
```python
# Numeric operations
a = 10
b = 3
print(a + b) # Output: 13
print(a // b) # Output: 3
# String operations
name = "Python"
print(name * 2) # Output: "PythonPython"
# List operations
numbers = [1, 2, 3]
numbers.append(4)
print(numbers) # Output: [1, 2, 3, 4]
# Dictionary operations
person = {'name': 'Alice', 'age': 25}
print(person['name']) # Output: "Alice"
```
This covers the fundamental data types and operators in Python. Let me know if you need further clarification!
Python Data Types and Operators ### Data Types Python supports several built-in data types, including: 1. **Numeric Types** - `int`: Integer (e.g., `5`, `-3`, `0`) - `float`: Floating-point number (e.g., `3.14`, `-0.001`, `2.0`) - `complex`: Complex number (e.g., `1 + 2j`) 2. **Sequence Types** - …
2023-06-272023-06-27421 words2 mins
Obsidian Basics
Obsidian Basics
2023-05-142023-05-14359 words2 mins
Standards for Friendship (Five Principles of Peaceful Coexistence)
Standards for Making Friends (Five Principles of Peaceful Coexistence)
2023-01-282023-01-280 words0 mins
Poems written during the 2023 Spring Festival
Poems written during the 2023 Spring Festival
2023-01-272023-01-27294 words2 mins
Thoughts on *The Wandering Earth 2*
Thoughts on *The Wandering Earth 2*
2023-01-122023-01-12525 words3 mins
*Journey* — A Pilgrimage of Friendship and Life
*Journey* — A Pilgrimage of Friendship and Life
2023-01-112023-01-11379 words2 mins
**Review of "Glimmering Mirror"**
If you’re a player primarily interested in the art style and have lower expectations for other aspects, I’d currently still recommend this game.
2023-01-022023-01-02239 words2 mins
"My Three-Body: Zhang Beihai Biography" and "Three-Body" Animation
After watching too many thesis defenses, I went back for a second viewing of The Legend of Zhang Beihai to cleanse my eyes.
2023-01-012023-01-01394 words2 mins
2022 Year in Review
Another year has passed in the blink of an eye.
2022-12-162022-12-16958 words5 mins
*Reflections on "Senren*Banka"*
Senren*Banka
Yesterday afternoon and evening, I spent eight hours straight completing the Murasame route. This morning, I went back to listen to the OST again—utterly unforgettable. It’s safe to say that Yuzusoft’s works are indeed a great escape from reality.