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 |

相关推荐
wxwx_bscxy32218 分钟前
基于Python新冠疫情可视化分析系统的设计与实现
java·数据库·spring boot·python·微信小程序·sqlite
TechWayfarer1 小时前
Cloudflare 9·15新政倒计时:用IP风险画像识别AI爬虫,防止误伤Googlebot
网络·人工智能·爬虫·python·tcp/ip·网络安全
禹凕1 小时前
滑动窗口算法实战指南
python·算法
论文复现现场2 小时前
RTX 4090 24GB 能跑 Qwen3.8-27B 吗?单卡显存计算与云端部署指南
人工智能·python·云计算·llama·gpu算力
Patrick在香港2 小时前
模型路由器实测:12 个任务省 77%,旗舰过载时的降级要打出显式标记
python·llm·智能路由器·api·架构设计·成本优化
Looooking2 小时前
Python 之 jwt 令牌生成和校验
python·jwt
2601_962295993 小时前
嵌入式开发语言用哪个最好,C,python或者其他
c语言·python·嵌入式开发·开发效率·系统资源
菜鸡66664 小时前
绕过cf验证,部署 FlareSolverr 服务使用request处理
python·cloudflare
前端 贾公子4 小时前
第10章:RAG(2)
开发语言·python
2601_962299495 小时前
使用 Python 将 CSV 转为 PDF(含表格样式美化)
python·pdf·csv·spire.xls·表格样式