python学习笔记#1简单数据类型

python学习笔记#1简单数据类型


前言

python是一门解释型语言,学习基础的python的使用,认识字符串及其基本用法。


一、简单数据的类型?

现阶段学习的简单的数据类型
整型:int (1,2,3,4…整数)
浮点型:float (1.1,2.2,3.3…小数)
复数:complex (a+bj,复数形式)
布尔:bool (ture/false,真或假, 默认ture=1,false=0)
字节:bytes (b’123’,小写b表示字节)
字符串:string (“word” 字符串,‘‘单引号或者""双引号,’’‘’''三个单引号或者"“”“”"三个双引号的表示形式)
空类型:None

二、基本使用步骤

1.打印简单的数据类型

代码如下:

print("Hello World!!!")
int_var = 1
print(type(int_var))
float_var = 1.1
print(type(float_var))
complex_var = 1 + 2j
print(type(complex_var))
str_var = "123"
print(type(str_var))
bytes_var = b'101'
print(type(bytes_var))
bool_var = True
print(type(bool_var))
None_var = None
print(type(None_var))

可以得到相应结果

Hello World!!!
<class 'int'>
<class 'float'>
<class 'complex'>
<class 'str'>
<class 'bytes'>
<class 'bool'>
<class 'NoneType'>

在打印操作中还有一些小的细节

print("hello world")
print("hello\nworld")
print("hello\"world")

结果如下

hello world
hello
world
hello"world

可以知道,\n为主动换行,\开头的字符又被称为转义字符

# 转义字符
# \n 换行符:换行
print("hello\nworld")
# \t 制表符:即tab键,光标移动到下组默认缩进(大概是4个空格)前
print("hello\tworld")
# \r 回车符:光标移动到本行的开头(删掉本行之前的)
print("hello\rworld")
# \b 退格符:退格(Backspace),将光标位置移到前一位。
print("hello\bworld")
# 原字符,不希望字符串中的转义字符起作用,就使用原字符,就是在字符串之前加上r, 或者R
print(r"hello\nworld")
# \\为反斜线,\'为单引号,\"为双引号,\为在字符串结尾,表示一行未完转在下一行写
print("hello\
world")
# 注意,最后一个字符不能是反斜杠
# print(r"hello\nword\")
hello
world
hello	world
world
hellworld
hello\nworld
helloworld

2.数据变量定义

格式为变量名 = 值(variable_name = value)
在Python中,变量类似一个标签,可以通过变量来访问所对应的值,变量的类型由值来决定
查看变量属性的函数:
print(variable_name) : 打印变量内容
type(variable): 变量类型
id(variable): 查看变量标识
(注释代码使用ctrl + / 注释,也可在头尾加"""三双引号区域注释)


总结

本文仅仅简单学习了python的部分数据类型的使用,python还有更多内容等待学习。
(本文为初学者学习笔记,若有错误之处,感谢大佬指正!)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值