1、第一次学Python,那么我们就先向Python打个招呼吧!
print("hello world")
2、注释:分为单行注释、多行注释
单行注释:会在文字前面加个#号,快捷键为ctrl + /
多行注释:可以用单引号、也可以用双引号
单引号:’’’ 你的注释 ‘’’ 双引号:""“你的注释 “””
‘’’
第一行代码,
第二行代码,
…
‘’’
3、input的使用:在控制台上输入数据
name = input('请输入数据:')
print(name)
输出结果:
D:\软件\python\python.exe D:/zuoye/1.py
请输入数据:11
11
Process finished with exit code 0
4、数据类型
# 整型, 整数 int
# 打印 type(), 获取数据的数据类型
print(type(5))
# 浮点数 float
print(type(1.2))
# 布尔, bool
print(type(True))
# 列表, list
print(type([1,2,3]))
# 字典, dict
print(type({"name": "yuze"}))
# 元组, tuple
print(type((1,2,3)))
# 集合, set
print(type({1,2,3}))
# 字符串
print(type("1"))
print(type(2.0))
print(type(False))
print(type('false'))
运行结果
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'list'>
<class 'dict'>
<class 'tuple'>
<class 'set'>
<class 'str'>
<class 'float'>
<class 'bool'>
<class 'str'>
数据类型的转换
int --str
t = 2
print(type(str(t)))
print(type(str(False))
运行结果:
D:\软件\python\python.exe D:/zuoye/1.py
<class 'str'>
<class 'str'>
Process finished with exit code 0
基本上所有的类型都可以转化为字符串
5、变量
变量的命名规范:只可以使用数字、字母和下划线组成(不能使用数字开头)
变量命名尽量做到见名知意(尽量不要使用拼音)
常见的命令命名表示法(风格):
1、纯小写字母,每个单词之间用下划线隔开
max_num = 199999
2、大驼峰命名法:每个单词的第一个字母大写
MaxNum = 1999999
3、小驼峰命名法:第一单词开头字母小写,后面单词第一个字母大写
maxNum = 199999
_bbx_ = 10
y8_ = 20
# 求x+y的结果
name = "小明"
age = 18
gender = "男"
x = 10
y = 20
# print(y + x)
print(name)
print(age)
print(gender)
# # 尽量不要使用拼音做遍历名字
# xingming = '小红'