Basic knowledge of Python

The overall introduction is here

Introduction to Python

1. Variable Definition

You needn't assign a type to a variable, because Python interpreter will automatically judge the type. You needn't declare a variable before define. The following is an example of how to state a variable:

python 复制代码
a = 1

b = "hello"

c = 3.14159

As you can see, definition of variable is simple, just use = .

The name of variable shoule make up letters, $, numbers, and _ . A variable mustn't begin with a number.

Note that in the instance above, a,b and c is the reference of the variable. That is, 1 "hello" and 3.14159 is in the heap memory and a,b and c just their alias. It is important.

2. Comment

Comment is important for us to understand the function of our code. We use # to indicate the line is a comment.

python 复制代码
# This is a comment
# The comment will be ignored by the interpreter.

a = 1 # You can also add a comment here, too.
b = "hello"
c = 3.14159

3. Type of variable

We needn't declare the type of a variable, but it doesn't mean that a variable hasn't a type.

There are many types in Python:

|----------|-----------------------------------------------------------|-------------|
| int | integer | a = 10 |
| float | folat number | a = 1.2 |
| complex | complex number | a = 1 + 2j |
| bool | True or False | a = False |
| str | a string of charactors | a = "hello" |
| Sequence | a special type of variable which we will explore it later | |
| None | indicates that a variable is empty | a = None |

When you define a variable, the interpreter will judge the type of the variable automatically.

4. build-in functions

We haven't explore what is function now, so if you can't understand what functions are, you can just memorize the form and use it. You will definitely understand it later.

|---------|---------------------------------------------------------------------------------------------------------------|--------------------------|
| print() | a powerful function which can print out content to your terminal, which can receive almost any type of input. | print(1) |
| | | print("hello") |
| | | print(...) |
| len() | It will return the "length" of an object. The "length" is defined by the object. We will talk about it later. | len(1,2,1) #return 3 |

相关推荐
言乐6几秒前
Python体现逻辑回归和决策树的区别
开发语言·python·算法·决策树·逻辑回归
LOVE️YOU6 分钟前
Python 类与对象的核心逻辑:从 self、cls 到点号、括号与链式调用
开发语言·python
空心木偶☜19 分钟前
A2A2A(多智能体协作)
开发语言·python·ai·ai编程
Cc.Y22 分钟前
Java零基础入门:类与对象深度掌握 —— 从“零散变量“到“打包管理“
java·开发语言·python
AINative软件工程32 分钟前
LLM Prompt Registry 工程实践:集中管理 Prompt,让模型调用不再散落在代码各处
后端·python·llm
Patrick在香港40 分钟前
MCP 的 initialize 握手真的没了?67 行标准库实测 2026-07-28 规范
python·agent·claude·mcp·json-rpc
vx_Biye_Design43 分钟前
springboot角色扮演服务平台65161-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·python·spring·课程设计
追烽少年x1 小时前
从零构建一个3D点云预览器:Python + PySide6 + pyqtgraph 实战
python·3d
weixin_440401691 小时前
质朴的爬虫+数据处理
爬虫·python·数据分析·pandas
估值探索者1 小时前
【Python量化系统工程实战 #01】数据存储选型 CSVSQLiteMySQL 对比与 SQLite 实战建库
开发语言·jvm·python·sqlite·api接口·数据api接口·股票数据api接口