浩明-空间 浩明-空间
首页
  • Unity

    • 类比法学c#
  • 学习笔记

    • 《JavaScript高级程序设计》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • typescript杂谈

    • 为什么要用ts
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • vim学习
  • webgl基础
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 悟道
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

储浩明

热爱编程的小明
首页
  • Unity

    • 类比法学c#
  • 学习笔记

    • 《JavaScript高级程序设计》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • typescript杂谈

    • 为什么要用ts
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • vim学习
  • webgl基础
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 悟道
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Python基础知识与js,c#,ts类比
    • Python变量与数据结构
    • 类比js
    • 类比ts
    • 类比C
    • python运算符
    • 类比js运算符
    • python 控制结构
    • 类比js控制结构
    • python 函数和模块
    • 类比js 函数和模块
    • python 类和对象
    • 类比js 类和对象
  • Python
chuhaoming
2025-03-19
目录

Python基础知识与js,c#,ts类比

# Python变量与数据结构

变量与数据类型 :变量可用来存储数据,Python 中有多种数据类型,像整数(int)、浮点数(float)、字符串(str)、布尔值(bool)等。

# 整数
age = 25
# 浮点数
height = 1.75
# 字符串
name = "John"
# 布尔值
is_student = True

1
2
3
4
5
6
7
8
9

# 类比js

let age=25;

const height=1.75;

let name ="john"

is_student=true 

1
2
3
4
5
6
7
8

# 类比ts

let age: number = 25;
// 浮点数
let height: number = 1.75;
// 字符串
let name: string = "John";
// 布尔值
let is_student: boolean = true;
1
2
3
4
5
6
7

# 类比C

using System;

class Program
{
    static void Main()
    {
        // 整数
        int age = 25;
        // 浮点数
        double height = 1.75;
        // 字符串
        string name = "John";
        // 布尔值
        bool is_student = true;

        // 输出变量的值,可根据需求保留或删除
        Console.WriteLine($"年龄: {age}");
        Console.WriteLine($"身高: {height}");
        Console.WriteLine($"姓名: {name}");
        Console.WriteLine($"是否为学生: {is_student}");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# python运算符

运算符:包括算术运算符(+、-、*、/ 等)、比较运算符(==、!=、>、< 等)和逻辑运算符(and、or、not)。

# 算术运算
result = 5 + 3
# 比较运算
is_equal = (5 == 3)
# 逻辑运算
is_valid = (age > 18) and is_student

1
2
3
4
5
6
7

# 类比js运算符

// 算术运算
let result = 5 + 3;
// 比较运算
let is_equal = (5 === 3);
// 假设 age 和 is_student 已经定义
let age = 25;
let is_student = true;
// 逻辑运算
let is_valid = (age > 18) && is_student;


1
2
3
4
5
6
7
8
9
10
11

# python 控制结构

包含条件语句(if - elif - else)和循环语句(for、while)。


# 条件语句
if age >= 18:
    print("成年人")
else:
    print("未成年人")

# for循环
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

# while循环
count = 0
while count < 5:
    print(count)
    count = count + 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 类比js控制结构

// 假设 age 已经定义
let age = 25;
// 条件语句
if (age >= 18) {
    console.log("成年人");
} else {
    console.log("未成年人");
}

// for循环
const fruits = ["apple", "banana", "cherry"];
for (let fruit of fruits) {
    console.log(fruit);
}

// while循环
let count = 0;
while (count < 5) {
    console.log(count);
    count = count + 1;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# python 函数和模块

函数:函数是一段可重复使用的代码块,能接收参数并返回值。

模块:模块是包含 Python 代码的文件,可导入并使用其中的函数和变量。

def add_numbers(a, b):
    return a + b

sum_result = add_numbers(3, 5)
print(sum_result)

import math

# 使用 math 模块的函数
square_root = math.sqrt(16)
print(square_root)

1
2
3
4
5
6
7
8
9
10
11
12

# 类比js 函数和模块


 function add_numbers(a,b){
    return a+b
 }
 const  sum_result=add_numbers(3,5)
 console.log(sum_result)


import math from math

const square_root = math.sqrt(16)
 console.log(square_root)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# python 类和对象

类和对象:类是对象的蓝图,对象是类的实例。

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def introduce(self):
        print(f"我叫 {self.name},今年 {self.age} 岁。")

# 创建对象
person = Person("John", 25)
person.introduce()

1
2
3
4
5
6
7
8
9
10
11
12

# 类比js 类和对象

class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

    introduce() {
        console.log(`我叫 ${this.name},今年 ${this.age} 岁。`);
    }
}

// 创建对象
const person = new Person("John", 25);
person.introduce();



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
编辑 (opens new window)
上次更新: 2025/03/19, 14:21:39
最近更新
01
ARG
12-03
02
插件开发的核心原则
12-03
03
c#中的值类型和引用类型
08-19
更多文章>
Theme by Vdoing | Copyright © 2019-2025 Haoming chu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式